k8s flannel安装以后网络不能ping通的问题解决

场景一:相同的node,不同的pod不能ping的问题

k8s安装好以后,获取信息如下:

k8s安装好以后,获取信息如下:
[root@cent7-102 ~]# kubectl get all -n kube-system -o wide
NAME                                    READY   STATUS    RESTARTS   AGE    IP               NODE        NOMINATED NODE   READINESS GATES
pod/coredns-5644d7b6d9-48pmd            1/1     Running   0          147m   10.244.2.3       cent7-104              
pod/coredns-5644d7b6d9-xt2vm            1/1     Running   0          14m    10.244.1.7       cent7-103              
pod/etcd-cent7-102                      1/1     Running   0          159m   192.168.56.102   cent7-102              
pod/kube-apiserver-cent7-102            1/1     Running   0          160m   192.168.56.102   cent7-102              
pod/kube-controller-manager-cent7-102   1/1     Running   0          159m   192.168.56.102   cent7-102              
pod/kube-flannel-ds-9x465               1/1     Running   0          20s    192.168.56.103   cent7-103              
pod/kube-flannel-ds-r6ntq               1/1     Running   0          20s    192.168.56.102   cent7-102              
pod/kube-flannel-ds-x2tvf               1/1     Running   0          20s    192.168.56.104   cent7-104              
pod/kube-proxy-j55sg                    1/1     Running   0          157m   192.168.56.104   cent7-104              
pod/kube-proxy-qslmb                    1/1     Running   0          160m   192.168.56.102   cent7-102              
pod/kube-proxy-x7tfc                    1/1     Running   0          158m   192.168.56.103   cent7-103              
pod/kube-scheduler-cent7-102            1/1     Running   0          160m   192.168.56.102   cent7-102              

NAME               TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE    SELECTOR
service/kube-dns   ClusterIP   10.96.0.10           53/UDP,53/TCP,9153/TCP   160m   k8s-app=kube-dns

NAME                             DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR                 AGE    CONTAINERS     IMAGES                           SELECTOR
daemonset.apps/kube-flannel-ds   3         3         3       3            3                                   20s    kube-flannel   quay.io/coreos/flannel:v0.15.0   app=flannel
daemonset.apps/kube-proxy        3         3         3       3            3           beta.kubernetes.io/os=linux   160m   kube-proxy     k8s.gcr.io/kube-proxy:v1.16.4    k8s-app=kube-proxy

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE    CONTAINERS   IMAGES                     SELECTOR
deployment.apps/coredns   2/2     2            2           161m   coredns      k8s.gcr.io/coredns:1.6.2   k8s-app=kube-dns

NAME                                 DESIRED   CURRENT   READY   AGE    CONTAINERS   IMAGES                     SELECTOR
replicaset.apps/coredns-5644d7b6d9   2         2         2       160m   coredns      k8s.gcr.io/coredns:1.6.2   k8s-app=kube-dns,pod-template-hash=5644d7b6d9

步骤一:检查所有机器上的docker ip

ip addr | grep docker

引起原因:可能是采用虚拟机安装时,所以的机器是复制一个机器引起所以的 docker0的ip相同

处理方式:

方式一:配置docker配置文件 vim /etc/docker/daemon.json 添加上 "bip":"xxx.xxx.xxx.xxx" 方式二:修改docker ip ip addr add 172.7.103.1/24 dev docker0 ip addr del dev docker0 172.7.101.1/24 ip addr flush docker0 ip addr add dev docker0 172.7.103.1/24

步骤二:检查路由表

k8s flannel安装以后网络不能ping通的问题解决_第1张图片

[root@cent7-102 ~]# ip route 
default via 192.168.56.1 dev enp0s3 proto static metric 100 
10.244.0.0/24 dev cni0 proto kernel scope link src 10.244.0.1 linkdown 
10.244.1.0/24 via 10.244.1.0 dev flannel.1 onlink 
10.244.2.0/24 via 10.244.2.0 dev flannel.1 onlink 
192.18.0.0/16 dev br-e9cecf8bbf3c proto kernel scope link src 192.18.0.1 linkdown 
192.168.56.0/24 dev enp0s3 proto kernel scope link src 192.168.56.102 metric 100 
192.168.102.0/24 dev docker0 proto kernel scope link src 192.168.102.1 linkdown 

[root@cent7-102 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.56.1    0.0.0.0         UG    100    0        0 enp0s3
10.244.0.0      0.0.0.0         255.255.255.0   U     0      0        0 cni0
10.244.1.0      10.244.1.0      255.255.255.0   UG    0      0        0 flannel.1
10.244.2.0      10.244.2.0      255.255.255.0   UG    0      0        0 flannel.1
192.18.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-e9cecf8bbf3c
192.168.56.0    0.0.0.0         255.255.255.0   U     100    0        0 enp0s3
192.168.102.0   0.0.0.0         255.255.255.0   U     0      0        0 docker0

场景二:相同的node,不同的pod不能ping的问题(测试本机到本机,测试本机到外网,再测试本机到其它node)

步骤一:登录到pod机器上,进行ping确认

# 可以查看域名解析 
nslookup www.baidu.com  -- 如果这个不能的通的话,就查看 kube-system 中的 service/kube-dns 与 /etc/resolv.conf的配置是否一致

# ping pod所在的node ip
ping local_node_ip  :确认pod与本机通信 如果不能需要配置 路由表

# ping pod所在的node的pod ip
ping local_node_pod_ip  :确认pod与本机其他pod通信 如果不能需要配置 路由表

# ping 不同的node ip : 确认pod与其他node能通信 如果不能需要配置 路由表
ping other_node_ip 
#  10.244.2.0      10.244.2.0      255.255.255.0   UG    0      0        0 flannel.1  (这个k8s应该有自动生成)

# ping other_node_pod_id 确认pod与其他node能通信 如果不能需要配置 路由表
ping other_node_pod_ip
# 配置如下 route add -net 0.0.0.0 gw 192.168.56.1 dev enp0s3  (192.168.56.1 这个是你自己机器的gateway)

这是我的有道笔记共享,我会不断更新 有道云笔记

你可能感兴趣的:(K8s,网络,kubernetes,docker)