2016-05-19 115 views
0

我已經完成了所有kubernetes DNS服務配置,並測試它運行正常。但我怎麼能從serviceName(DNS域名)訪問窗格?爲什麼我無法在kubernetes羣集的一個羣集中連接其他羣集?

莢列表

[[email protected] ~]# kubectl get pod 
NAME   READY  STATUS RESTARTS AGE 
bj001-y1o2i 3/3  Running 12   20h 
dns-itc8d  3/3  Running 18   1d 
nginx-rc5bh 1/1  Running 1   15h 

服務列表

[[email protected] ~]# kb get svc 
NAME   CLUSTER_IP  EXTERNAL_IP PORT(S)    SELECTOR AGE 
bj001  10.254.54.162 172.16.2.51 30101/TCP,30102/TCP app=bj001 1d 
dns   10.254.0.2  <none>  53/UDP,53/TCP   app=dns  1d 
kubernetes 10.254.0.1  <none>  443/TCP    <none>  8d 
nginx  10.254.72.30  172.16.2.51 80/TCP    app=nginx 20h 

端點

[[email protected] ~]# kb get endpoints 
NAME   ENDPOINTS       AGE 
bj001  172.17.12.3:18010,172.17.12.3:3306 1d 
dns   172.17.87.3:53,172.17.87.3:53  1d 
kubernetes 172.16.2.50:6443      8d 
nginx  172.17.12.2:80      20h 
在nginx的p

od,我可以ping pod bj001,並找到DNS名稱,但不能ping dns域名。

這樣的:

[[email protected] ~]# kb exec -it nginx-rc5bh sh 
sh-4.2# nslookup bj001 
Server:  10.254.0.2 
Address: 10.254.0.2#53 

Name: bj001.default.svc.cluster.local 
Address: 10.254.54.162 

sh-4.2# ping 172.17.12.3 
PING 172.17.12.3 (172.17.12.3) 56(84) bytes of data. 
64 bytes from 172.17.12.3: icmp_seq=1 ttl=64 time=0.073 ms 
64 bytes from 172.17.12.3: icmp_seq=2 ttl=64 time=0.082 ms 
64 bytes from 172.17.12.3: icmp_seq=3 ttl=64 time=0.088 ms 
64 bytes from 172.17.12.3: icmp_seq=4 ttl=64 time=0.105 ms 
^C 
--- 172.17.12.3 ping statistics --- 
4 packets transmitted, 4 received, 0% packet loss, time 2999ms 
rtt min/avg/max/mdev = 0.073/0.087/0.105/0.011 ms 

sh-4.2# ping bj001 
PING bj001.default.svc.cluster.local (10.254.54.162) 56(84) bytes of data. 
^C 
--- bj001.default.svc.cluster.local ping statistics --- 
2 packets transmitted, 0 received, 100% packet loss, time 999ms 

回答

1

我發現我的錯。 kubernetes使用iptables與不同的pod進行傳輸。所以我們應該這樣做,我們所有使用的端口都應該放在{spec.ports}中,就像我的問題一樣,必須打開18010端口。

[[email protected] ~]# kb get svc 
NAME   CLUSTER_IP  EXTERNAL_IP PORT(S)    SELECTOR AGE 
bj001  10.254.91.218 <none>  3306/TCP,18010/TCP app=bj001 41m 
dns   10.254.0.2  <none>  53/UDP,53/TCP  app=dns  1d 
kubernetes 10.254.0.1  <none>  443/TCP    <none>  8d 
nginx  10.254.72.30 172.16.2.51 80/TCP    app=nginx 1d 
+0

建議使用[** telnet IP port **]測試ip連接。 –

+0

一般而言,您應該允許節點之間的所有連接,因爲可以隨機分配許多端口。 –