【K8S运维知识汇总】第3天4:详解flanneld工作原理
flanneld实际上只是在宿主机上的路由表中添加了静态路由来完成通信[root@hdss7-21 ~]# route -nKernel IP routing tableDestinationGatewayGenmaskFlags Metric RefUse Iface0.0.0.010.4.7.2540.0.0.0UG10000 ens3310.4.7.0.
·
flanneld实际上只是在宿主机上的路由表中添加了静态路由来完成通信
[root@hdss7-21 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.4.7.254 0.0.0.0 UG 100 0 0 ens33
10.4.7.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
172.7.21.0 0.0.0.0 255.255.255.0 U 0 0 0 docker0
172.7.22.0 10.4.7.22 255.255.255.0 UG 0 0 0 ens33
清除原有规划,实验VxLAN模型
[root@hdss7-21 ~]# supervisorctl stop flanneld-7-21
flanneld-7-21: stopped
[root@hdss7-21 ~]# supervisorctl status
etcd-server-7-21 RUNNING pid 12272, uptime 6 days, 21:27:13
flanneld-7-21 STOPPED Jul 03 09:46 AM
kube-apiserver-7-21 RUNNING pid 13277, uptime 5 days, 22:00:54
kube-controller-manager-7-21 RUNNING pid 64267, uptime 1 day, 23:23:01
kube-kubelet-7-21 RUNNING pid 17290, uptime 4 days, 15:21:44
kube-proxy-7-21 RUNNING pid 55520, uptime 4 days, 12:07:09
kube-scheduler-7-21 RUNNING pid 64261, uptime 1 day, 23:23:01
[root@hdss7-21 ~]# ps -ef | grep flanneld
root 26835 1 0 07:08 ? 00:00:03 ./flanneld --public-ip=10.4.7.21 --etcd-endpoints=https://10.4.7.12:2379,https://10.4.7.21:2379,https://10.4.7.22:2379 --etcd-keyfile=./cert/client-key.pem --etcd-certfile=./cert/client.pem --etcd-cafile=./cert/ca.pem --iface=ens33 --subnet-file=./subnet.env --healthz-port=2401
root 66841 55814 0 09:46 pts/2 00:00:00 grep --color=auto flanneld
[root@hdss7-21 ~]# kill -9 26835
[root@hdss7-21 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.4.7.254 0.0.0.0 UG 100 0 0 ens33
10.4.7.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
172.7.21.0 0.0.0.0 255.255.255.0 U 0 0 0 docker0
172.7.22.0 10.4.7.22 255.255.255.0 UG 0 0 0 ens33
[root@hdss7-21 ~]# route del -net 172.7.22.0/24 gw 10.4.7.22
[root@hdss7-21 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.4.7.254 0.0.0.0 UG 100 0 0 ens33
10.4.7.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
172.7.21.0 0.0.0.0 255.255.255.0 U 0 0 0 docker0
# 清除etcd配置
[root@hdss7-22 etcd]# ./etcdctl rm /coreos.com/network/config
PrevNode.Value: {"Network": "172.7.0.0/16", "Backend": {"Type": "host-gw"}}
[root@hdss7-22 etcd]# ./etcdctl get /coreos.com/network/config
Error: 100: Key not found (/coreos.com/network/config) [23]
启动supervisord服务,并查看网卡信息
[root@hdss7-21 ~]# supervisorctl start flanneld-7-21
flanneld-7-21: started
[root@hdss7-21 ~]# supervisorctl status
[root@hdss7-21 ~]# ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.7.21.1 netmask 255.255.255.0 broadcast 172.7.21.255
inet6 fe80::42:14ff:fea6:e81c prefixlen 64 scopeid 0x20<link>
ether 02:42:14:a6:e8:1c txqueuelen 0 (Ethernet)
RX packets 123 bytes 12491 (12.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 129 bytes 9189 (8.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.4.7.21 netmask 255.255.255.0 broadcast 10.4.7.255
inet6 fe80::95b5:7d01:18dd:8782 prefixlen 64 scopeid 0x20<link>
inet6 fe80::9d0e:cf49:764f:a162 prefixlen 64 scopeid 0x20<link>
inet6 fe80::758c:3945:4b43:ef1e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:88:a2:40 txqueuelen 1000 (Ethernet)
RX packets 9877686 bytes 2073770132 (1.9 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9452027 bytes 1375722978 (1.2 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
flannel.1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
inet 172.7.21.0 netmask 255.255.255.255 broadcast 0.0.0.0
inet6 fe80::a0fc:49ff:fed4:e884 prefixlen 64 scopeid 0x20<link>
ether a2:fc:49:d4:e8:84 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 8 overruns 0 carrier 0 collisions 0
[root@hdss7-21 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.4.7.254 0.0.0.0 UG 100 0 0 ens33
10.4.7.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
172.7.21.0 0.0.0.0 255.255.255.0 U 0 0 0 docker0
172.7.22.0 172.7.22.0 255.255.255.0 UG 0 0 0 flannel.1
直接路由模式
#智能模式,根据网络flanneld自行选择不同的模式
./etcdctl set /coreos.com/network/config '{"Network": "172.7.0.0/16", "Backend": {"Type": "VxLAN","Directrouting":"true"}}'
PrevNode.Value: {"Network": "172.7.0.0/16", "Backend": {"Type": "VxLAN"}}
手动实现flanneld功能
手动添加路由表:
10.4.7.22主机上添加路由表:
10.4.7.21主机上添加路由表:
修改iptables规则:
10.4.7.21主机上添加iptables规则:
10.4.7.22主机上添加iptables规则:
更多推荐
已为社区贡献48条内容
所有评论(0)