2017-05-18 51 views
0

我在我的3個virtualbox虛擬機上安裝了kubernetes集羣。 3 vms全部運行Ubuntu14.04並禁用ufw。 Kubernetes versin是1.6。這裏是我的配置文件,用於創建pod和服務。Kubernetes節點端口無法成功公開

波德pod.yaml

apiVersion: v1 
kind: ReplicationController 
metadata: 
    name: frontend 
    labels: 
    name: frontend 
spec: 
    replicas: 3 
    selector: 
    name: frontend 
    template: 
    metadata: 
     labels: 
     name: frontend 
    spec: 
     imagePullSecrets: 
     - name: regsecret 
     containers: 
     - name: frontend 
     image: hub.allinmoney.com/kubeguide/guestbook-php-frontend 
     env: 
     - name: GET_HOSTS_FROM 
      value: env 
     ports: 
     - containerPort: 80 

服務service.yaml

apiVersion: v1 
kind: Service 
metadata: 
    name: frontend 
    labels: 
    name: frontend 
spec: 
    type: NodePort 
    ports: 
    - port: 80 
     targetPort: 31000 
     nodePort: 31000 
    selector: 
    name: frontend 

我創建NodePort類型的服務。當我運行命令kubectl create -f service.yaml,它輸出像下面,我無法找到任何KUBE節點暴露的端口31000:

You have exposed your service on an external port on all nodes in your 
cluster. If you want to expose this service to the external internet, you may 
need to set up firewall rules for the service port(s) (tcp:31000) to serve traffic. 

See http://releases.k8s.io/release-1.3/docs/user-guide/services-firewalls.md for more details. 

誰能告訴如何解決這個或者給我任何提示?

+1

嘗試將targetPort設置爲80 – JazzCat

+0

kube-system是否在節點上運行?你可以發佈'iptables-save'的輸出嗎? –

回答

1

正如錯誤消息中所述,您需要爲節點設置防火牆規則以接受節點端口上的流量(默認值:30000-32767)。

防火牆規則例如

Name: [firewall-rule-name] 
Targets: [node-target-name, node-target2-name] 
Source filters: IP ranges: 0.0.0.0/0 
Protocols/ports: tcp:80,443,30000-32767 
Action: Allow 
Priority: 1000 
Network: default 

你TARGETPORT也是不正確的,它需要指向在POD(80端口)的相應端口。

+0

非常感謝。我找出了原因。 – Binary