我的工作 Docker 容器在 Kubernetes 上没有开放端口
My working Docker container has no open ports on Kubernetes
我有一个简单的 NodeJS 应用程序,我为其创建了一个图像。
我可以启动它并在本地与它交谈:
docker run -p 80:80 -it --rm --name test gcr.io/XXX/XXX:0.1
$ curl docker
=> Unauthorized
符合预期。
Kubernetes
webservice-复制-controller.yml:
apiVersion: v1
kind: ReplicationController
metadata:
name: harvester-webservice
spec:
replicas: 2
selector:
app: harvester-webservice
template:
metadata:
labels:
app: harvester-webservice
spec:
containers:
- name: harvester-webservice
image: gcr.io/XXX/XXX
ports:
- containerPort: 80
webservice-service.yml
apiVersion: v1
kind: Service
metadata:
name: harvester-webservice
labels:
name: harvester-webservice
spec:
type: LoadBalancer
ports:
-
port: 80
targetPort: 80
protocol: TCP
selector:
name: harvester-webservice
我已经启动集群如下:
$ kubectl create -f webservice-service.yml
$ kubectl create -f webservice-replication-controller.yml
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
harvester-webservice-controller-8qmkl 1/1 Running 0 11m
harvester-webservice-controller-chnky 1/1 Running 0 11m
$ kubectl get services
NAME LABELS SELECTOR IP(S) PORT(S)
harvester-webservice name=harvester-webservice name=harvester-webservice 10.NN.NN.NN 80/TCP
104.NN.NN.NN
kubernetes component=apiserver,provider=kubernetes <none> 10.NN.NN.NN 443/TCP
$ kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
harvester-webservice-controller harvester-webservice gcr.io/XXX/XXX app=harvester-webservice 2
curl 104.NNN.NNN.NNN
returns:
curl: (56) Recv failure: Connection reset by peer
curl 10.NNN.NNN.NNN
挂起
当我通过 ssh 进入容器并在 Node 应用程序上执行 docker logs
时,日志是它们应该的。
非常感谢所有提示或建议!
$ kubectl get endpoints
NAME ENDPOINTS
harvester-webservice <none>
kubernetes 104.NN.NN.NN:443
最好的,
马丁
将 webservice-service.yml
中的选择器更改为 app: harvester-webservice
,使其与 webservice-replication-controller.yml
中的标签匹配。
另请参阅 Kubernetes 中的 Services。
我有一个简单的 NodeJS 应用程序,我为其创建了一个图像。
我可以启动它并在本地与它交谈:
docker run -p 80:80 -it --rm --name test gcr.io/XXX/XXX:0.1
$ curl docker
=> Unauthorized
符合预期。
Kubernetes
webservice-复制-controller.yml:
apiVersion: v1
kind: ReplicationController
metadata:
name: harvester-webservice
spec:
replicas: 2
selector:
app: harvester-webservice
template:
metadata:
labels:
app: harvester-webservice
spec:
containers:
- name: harvester-webservice
image: gcr.io/XXX/XXX
ports:
- containerPort: 80
webservice-service.yml
apiVersion: v1
kind: Service
metadata:
name: harvester-webservice
labels:
name: harvester-webservice
spec:
type: LoadBalancer
ports:
-
port: 80
targetPort: 80
protocol: TCP
selector:
name: harvester-webservice
我已经启动集群如下:
$ kubectl create -f webservice-service.yml
$ kubectl create -f webservice-replication-controller.yml
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
harvester-webservice-controller-8qmkl 1/1 Running 0 11m
harvester-webservice-controller-chnky 1/1 Running 0 11m
$ kubectl get services
NAME LABELS SELECTOR IP(S) PORT(S)
harvester-webservice name=harvester-webservice name=harvester-webservice 10.NN.NN.NN 80/TCP
104.NN.NN.NN
kubernetes component=apiserver,provider=kubernetes <none> 10.NN.NN.NN 443/TCP
$ kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
harvester-webservice-controller harvester-webservice gcr.io/XXX/XXX app=harvester-webservice 2
curl 104.NNN.NNN.NNN
returns:
curl: (56) Recv failure: Connection reset by peer
curl 10.NNN.NNN.NNN
挂起
当我通过 ssh 进入容器并在 Node 应用程序上执行 docker logs
时,日志是它们应该的。
非常感谢所有提示或建议!
$ kubectl get endpoints
NAME ENDPOINTS
harvester-webservice <none>
kubernetes 104.NN.NN.NN:443
最好的, 马丁
将 webservice-service.yml
中的选择器更改为 app: harvester-webservice
,使其与 webservice-replication-controller.yml
中的标签匹配。
另请参阅 Kubernetes 中的 Services。