Why I can not connect other pod in one pod of the kubernetes cluster?

5/19/2016

I have done all kubernetes DNS service config,and test it running ok. but how could I access the pod from serviceName(DNS domain name)?

pod list

[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

service list

[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

endpoints

[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

in nginx pod, I can ping pod bj001,and find the DNS name,but can not ping dns domain name.

like this:

[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
-- Dongyang Dai
dns
kubernetes

1 Answer

5/19/2016

I have found my fault. kubernetes use iptables to transmit with different pod. So we should do that all we used port should be seted in the {spec.ports}, like my issue, the 18010 port must be opened.

[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
-- Dongyang Dai
Source: StackOverflow