我工作的Docker容器在Kubernetes上没有开放端口

时间:2015-11-06 12:54:28

标签: google-cloud-platform kubernetes

我有一个简单的NodeJS应用程序,我已经创建了一个图像。 我可以启动它并在本地与它交谈: docker run -p 80:80 -it --rm --name test gcr.io/XXX/XXX:0.1

$ curl docker => Unauthorized正如所料。

Kubernetes

web服务的复制-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

web服务-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返回: curl: (56) Recv failure: Connection reset by peer

curl 10.NNN.NNN.NNN只是挂起

当我进入容器并在Node应用程序上执行docker logs时,日志就像它们应该的那样。

所有提示或建议都非常适用!

$ kubectl get endpoints
NAME                   ENDPOINTS
harvester-webservice   <none>
kubernetes             104.NN.NN.NN:443

最佳, 马丁

1 个答案:

答案 0 :(得分:4)

webservice-service.yml中的选择器更改为app: harvester-webservice,使其与webservice-replication-controller.yml中的标签相匹配。

另见Kubernetes中的Services