为什么我无法在kubernetes集群的一个pod中连接其他pod?

时间:2016-05-19 05:05:39

标签: dns kubernetes

我已经完成了所有kubernetes DNS服务配置,并测试它运行正常。但是如何从serviceName(DNS域名)访问pod?

广告连播列表

[root@localhost ~]# 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

服务列表

[root@localhost ~]# 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

端点

[root@localhost ~]# 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 pod中,我可以ping pod bj001,找到DNS名称,但不能ping dns域名。

像这样:

[root@localhost ~]# 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 个答案:

答案 0 :(得分:1)

我发现了自己的错。 kubernetes使用iptables传输不同的pod。所以我们应该这样做,我们使用的所有端口都应该放在{spec.ports}中,就像我的问题一样,必须打开18010端口。

[root@localhost ~]# 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