2017-02-09 333 views
1

我创建了一个YAML文件,在一个窗格中有三个图像(它们需要通过127.0.0.1与海誓山盟进行通信)看起来,这一切都正常。我已经在yaml文件中定义了一个nodeport。Kubernetes nodeport不起作用

有定义applications一个部署它包含三个图像:

  • 接触-DB(MySQL数据库)
  • 前端(角网站)
  • 网核心(一个API)

我定义了三个服务,每个容器一个。在那里我已经定义了类型NodePort来访问它。

所以我检索到的服务来获得端口号:

NAME   CLUSTER-IP  EXTERNAL-IP PORT(S)   AGE 
contacts-db 10.103.67.74  <nodes>  3306:30241/TCP 1d 
front-end  10.107.226.176 <nodes>  80:32195/TCP  1d 
net-core  10.108.146.87 <nodes>  5000:30245/TCP 1d 

而且我在我的浏览器导航到http://:32195,它只是不断加载。这不是连接。这是完整的Yaml文件:

--- 
apiVersion: v1 
kind: Namespace 
metadata: 
    name: three-tier 
--- 
apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
    name: applications 
    labels: 
    name: applications 
    namespace: three-tier 
spec: 
    replicas: 1 
    template: 
    metadata: 
     labels: 
     name: applications 
    spec: 
     containers: 
     - name: contacts-db 
     image: mysql/mysql-server #TBD 
     env: 
      - name: MYSQL_ROOT_PASSWORD 
      value: quintor 
      - name: MYSQL_DATABASE 
      value: quintor #TBD 
     ports: 
     - name: mysql 
      containerPort: 3306 
     - name: front-end 
     image: xanvier/angularfrontend #TBD 
     resources: 
      requests: 
      cpu: 100m 
      memory: 100Mi 
     ports: 
     - containerPort: 80 
     - name: net-core 
     image: xanvier/contactsapi #TBD 
     resources: 
      requests: 
      cpu: 100m 
      memory: 100Mi 
     ports: 
     - containerPort: 5000 
--- 
apiVersion: v1 
kind: Service 
metadata: 
    name: contacts-db 
    labels: 
    name: contacts-db 
    namespace: three-tier 
spec: 
    type: NodePort 
    ports: 
    # the port that this service should serve on 
    - port: 3306 
    targetPort: 3306 
    selector: 
    name: contacts-db 
--- 
apiVersion: v1 
kind: Service 
metadata: 
    name: front-end 
    labels: 
    name: front-end 
    namespace: three-tier 
spec: 
    type: NodePort 
    ports: 
    - port: 80 
    targetPort: 80 #nodePort: 30001 
    selector: 
    name: front-end 
--- 
apiVersion: v1 
kind: Service 
metadata: 
    name: net-core 
    labels: 
    name: net-core 
    namespace: three-tier 
spec: 
    type: NodePort 
    ports: 
    - port: 5000 
    targetPort: 5000 #nodePort: 30001 
    selector: 
    name: net-core 
--- 

回答

3

服务的选择符与您的容器的标签相匹配。在你的情况下,定义的选择器指向容器,当选择容器时,它将变成什么都没有。

您必须重新定义您的服务才能使用一个选择器或将您的容器拆分到不同的Deployments/Pods。

要查看某个服务定义选择是否奏效,你可以检查它们:

kubectl get pods -l key=value 

如果结果是空的,你的服务将运行到空隙太大。

+1

此外,您还可以看到哪些服务实际上由具有'kubectl get endpoints'的端点(pod)支持 –

相关问题