flannel沒法跨主機ping通容器的解決方式

 

前幾天,出現了沒法跨主機ping通容器的狀況,致使一個node機網絡中斷,沒法訪問,排查過程以下。node

  1. 首先確認,宿主機node2是能夠ping通容器
    [root@node2 ~]# ping 10.1.19.3 
    PING 10.1.19.3 (10.1.19.3) 56(84) bytes of data.
    64 bytes from 10.1.19.3: icmp_seq=1 ttl=64 time=0.122 ms
    64 bytes from 10.1.19.3: icmp_seq=2 ttl=64 time=0.073 ms
    

      
    能夠ping通,進行下一步docker

  2. 確認,代理機到容器是否能夠ping通
    [root@node1 ~]# ping 10.1.19.3
    PING 10.1.19.3 (10.1.19.3) 56(84) bytes of data.
    ^C
    --- 10.1.19.3 ping statistics ---
    14 packets transmitted, 0 received, 100% packet loss, time 12999ms
    

      

    沒法ping通,檢查代理機
  3. 查看代理機的flannel子網段配置是否正常
    [root@node1 ~]# etcdctl ls /coreos.com/network/subnets
    /coreos.com/network/subnets/10.1.91.0-24
    /coreos.com/network/subnets/10.1.93.0-24
    /coreos.com/network/subnets/10.1.94.0-24
    /coreos.com/network/subnets/10.1.19.0-24
    /coreos.com/network/subnets/10.1.77.0-24
    

      

    網段配置是正常的,已經含有10.1.19.0-24 段了
  4. 返回去查看宿主機路由是否配置完整
    [root@node2 ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         192.168.19.51   0.0.0.0         UG    100    0        0 eth0
    10.1.19.0       0.0.0.0         255.255.255.0   U     0      0        0 docker0
    192.168.19.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0
    

      

    配置不完整,缺乏flannel路由配置
  5. 嘗試重啓flannel,若是沒法自動建立路由,則進行手動添加
    [root@node2 ~]# route add -net 10.1.0.0 netmask  255.255.0.0 dev flannel0
    [root@node2 ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         192.168.19.51   0.0.0.0         UG    100    0        0 eth0
    10.1.0.0        0.0.0.0         255.255.0.0     U     0      0        0 flannel0
    10.1.19.0       0.0.0.0         255.255.255.0   U     0      0        0 docker0
    192.168.19.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0
    

      

    建立完成以後沒確認網絡是否通了
  6. 確認網絡,若是依然沒法聯通,因爲flannel.1網卡和docker0網卡經過iptables的forward轉發,因此確保:
    1. 核中的forward功能開啓(當即生效,重啓後效果再也不)
      echo "1" > /proc/sys/net/ipv4/ip_forward
      

        

    2. 包不會被iptables的forward規則攔截網絡

      sudo iptables -P FORWARD ACCEPT
      
  7. 確認網絡是否聯通了
    [root@node1 ~]# ping 10.1.19.3
    PING 10.1.19.3 (10.1.19.3) 56(84) bytes of data.
    64 bytes from 10.1.19.3: icmp_seq=1 ttl=61 time=0.444 ms
    64 bytes from 10.1.19.3: icmp_seq=2 ttl=61 time=0.288 ms
    ^C
    --- 10.1.19.3 ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 999ms
    rtt min/avg/max/mdev = 0.288/0.366/0.444/0.078 ms
    

      

    網絡沒有問題了

以上代理

相關文章
相關標籤/搜索