kubernetes默认网关不路由到本地网络

时间:2016-11-13 01:41:06

标签: kubernetes

我在kubernetes上看到一个奇怪的问题,我不知道如何调试它。 k8s环境是使用2016-01-08 kube.vmdk通过kube-up为vsphere安装的

症状是pod中容器的dns无法正常工作。当我登录kube-dns服务检查设置时,一切看起来都正确。当我在本地网络外部ping时,它可以正常工作,但是当我在本地网络内部ping时,它无法访问任何主机。

对于以下我的主机网络是10.1.1.x,网关/ DNS服务器是10.1.1.1。

在kube-dns容器中:

(我可以通过ip在网络外ping,我可以ping通网关。由于名称服务器无法访问,dns无法正常工作)

kube@kubernetes-master:~$ kubectl --namespace=kube-system exec -ti kube-dns-v20-in2me -- /bin/sh
/ # cat /etc/resolv.conf
nameserver 10.1.1.1
options ndots:5
/ # ping google.com
^C
/ # ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=54 time=13.542 ms
64 bytes from 8.8.8.8: seq=1 ttl=54 time=13.862 ms
^C
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 13.542/13.702/13.862 ms
/ # ping 10.1.1.1
PING 10.1.1.1 (10.1.1.1): 56 data bytes
^C
--- 10.1.1.1 ping statistics ---
4 packets transmitted, 0 packets received, 100% packet loss
/ # netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         10.244.2.1      0.0.0.0         UG        0 0          0 eth0
10.244.2.0      *               255.255.255.0   U         0 0          0 eth0
/ # ping 10.244.2.1
PING 10.244.2.1 (10.244.2.1): 56 data bytes
64 bytes from 10.244.2.1: seq=0 ttl=64 time=0.249 ms
64 bytes from 10.244.2.1: seq=1 ttl=64 time=0.091 ms
^C
--- 10.244.2.1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.091/0.170/0.249 ms
主人

kube@kubernetes-master:~$ netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         10.1.1.1        0.0.0.0         UG        0 0          0 eth0
10.1.1.0        *               255.255.255.0   U         0 0          0 eth0
10.244.0.0      kubernetes-mini 255.255.255.0   UG        0 0          0 eth0
10.244.1.0      kubernetes-mini 255.255.255.0   UG        0 0          0 eth0
10.244.2.0      kubernetes-mini 255.255.255.0   UG        0 0          0 eth0
10.244.3.0      kubernetes-mini 255.255.255.0   UG        0 0          0 eth0
10.246.0.0      *               255.255.255.0   U         0 0          0 cbr0
172.17.0.0      *               255.255.0.0     U         0 0          0 docker0
kube@kubernetes-master:~$ ping 10.1.1.1
PING 10.1.1.1 (10.1.1.1) 56(84) bytes of data.
64 bytes from 10.1.1.1: icmp_seq=1 ttl=64 time=0.409 ms
64 bytes from 10.1.1.1: icmp_seq=2 ttl=64 time=0.481 ms
^C
--- 10.1.1.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.409/0.445/0.481/0.036 ms

版本:

kube@kubernetes-master:~$ kubectl version
Client Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.5", GitCommit:"5a0a696437ad35c133c0c8493f7e9d22b0f9b81b", GitTreeState:"clean", BuildDate:"2016-10-29T01:38:40Z", GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.5", GitCommit:"5a0a696437ad35c133c0c8493f7e9d22b0f9b81b", GitTreeState:"clean", BuildDate:"2016-10-29T01:32:42Z", GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/amd64"}

kubernetes-minion-2(10.244.2.1):

(Per @ der的回复添加来自10.244.2.1的信息)

kube@kubernetes-minion-2:~$ ip addr show cbr0
5: cbr0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc htb state UP group default
    link/ether 8a:ef:b5:fc:28:f4 brd ff:ff:ff:ff:ff:ff
    inet 10.244.2.1/24 scope global cbr0
       valid_lft forever preferred_lft forever
    inet6 fe80::38b5:44ff:fe8a:6d79/64 scope link
       valid_lft forever preferred_lft forever
kube@kubernetes-minion-2:~$ ping google.com
PING google.com (216.58.192.14) 56(84) bytes of data.
64 bytes from nuq04s29-in-f14.1e100.net (216.58.192.14): icmp_seq=1 ttl=52 time=11.8 ms
64 bytes from nuq04s29-in-f14.1e100.net (216.58.192.14): icmp_seq=2 ttl=52 time=11.6 ms
64 bytes from nuq04s29-in-f14.1e100.net (216.58.192.14): icmp_seq=3 ttl=52 time=10.4 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 10.477/11.343/11.878/0.624 ms
kube@kubernetes-minion-2:~$ ping 10.1.1.1
PING 10.1.1.1 (10.1.1.1) 56(84) bytes of data.
64 bytes from 10.1.1.1: icmp_seq=1 ttl=64 time=0.369 ms
64 bytes from 10.1.1.1: icmp_seq=2 ttl=64 time=0.456 ms
64 bytes from 10.1.1.1: icmp_seq=3 ttl=64 time=0.442 ms
^C
--- 10.1.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.369/0.422/0.456/0.041 ms
kube@kubernetes-minion-2:~$ netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         10.1.1.1        0.0.0.0         UG        0 0          0 eth0
10.1.1.0        *               255.255.255.0   U         0 0          0 eth0
10.244.0.0      kubernetes-mini 255.255.255.0   UG        0 0          0 eth0
10.244.1.0      kubernetes-mini 255.255.255.0   UG        0 0          0 eth0
10.244.2.0      *               255.255.255.0   U         0 0          0 cbr0
10.244.3.0      kubernetes-mini 255.255.255.0   UG        0 0          0 eth0
172.17.0.0      *               255.255.0.0     U         0 0          0 docker0
kube@kubernetes-minion-2:~$ routel
         target            gateway          source    proto    scope    dev tbl
        default           10.1.1.1                                     eth0
       10.1.1.0 24                       10.1.1.86   kernel     link   eth0
     10.244.0.0 24       10.1.1.88                                     eth0
     10.244.1.0 24       10.1.1.87                                     eth0
     10.244.2.0 24                      10.244.2.1   kernel     link   cbr0
     10.244.3.0 24       10.1.1.85                                     eth0
     172.17.0.0 16                      172.17.0.1   kernel     linkdocker0
       10.1.1.0          broadcast       10.1.1.86   kernel     link   eth0 local
      10.1.1.86              local       10.1.1.86   kernel     host   eth0 local
     10.1.1.255          broadcast       10.1.1.86   kernel     link   eth0 local
     10.244.2.0          broadcast      10.244.2.1   kernel     link   cbr0 local
     10.244.2.1              local      10.244.2.1   kernel     host   cbr0 local
   10.244.2.255          broadcast      10.244.2.1   kernel     link   cbr0 local
      127.0.0.0          broadcast       127.0.0.1   kernel     link     lo local
      127.0.0.0 8            local       127.0.0.1   kernel     host     lo local
      127.0.0.1              local       127.0.0.1   kernel     host     lo local
127.255.255.255          broadcast       127.0.0.1   kernel     link     lo local
     172.17.0.0          broadcast      172.17.0.1   kernel     linkdocker0 local
     172.17.0.1              local      172.17.0.1   kernel     hostdocker0 local
 172.17.255.255          broadcast      172.17.0.1   kernel     linkdocker0 local
            ::1              local                   kernel              lo
         fe80:: 64                                   kernel            eth0
         fe80:: 64                                   kernel            cbr0
         fe80:: 64                                   kernel         veth6129284
        default        unreachable                   kernel              lo unspec
            ::1              local                     none              lo local
fe80::250:56ff:fe8e:d580              local                     none              lo local
fe80::38b5:44ff:fe8a:6d79              local                     none              lo local
fe80::88ef:b5ff:fefc:28f4              local                     none              lo local
         ff00:: 8                                                      eth0 local
         ff00:: 8                                                      cbr0 local
         ff00:: 8                                                   veth6129284 local
        default        unreachable                   kernel              lo unspec

我如何诊断这里发生了什么?

谢谢!

2 个答案:

答案 0 :(得分:0)

首先,找出kubernetes-mini的内容。使用您向我们展示的2个节点完成了您所做的事情。 10.1.1.010.244.2.0之间的所有流量都会通过它。但是,10.1.1.0网可能路径不好。

答案 1 :(得分:0)

原来这是关于minions的默认nat路由规则的问题

$ iptables –t nat –vnxL
...
...
Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination
    ...
    80     4896 MASQUERADE  all  --  *      *       0.0.0.0/0           !10.0.0.0/8           /* kubelet: SNAT outbound cluster traffic */ ADDRTYPE match dst-type !LOCAL
...
...

这表明来自10.x.x.x网络的所有流量都被后处理规则忽略。

如果有人遇到此修复程序,请执行以下操作:

$ iptables -t nat -I POSTROUTING 1 -s 10.244.0.0/16 -d 10.1.1.1/32 -j MASQUERADE

其中10.244.x.x / 16是容器网络,10.1.1.1是网关ip