【K8S运维知识汇总】第3天4:详解flanneld工作原理

网友投稿 274 2022-09-07

【K8S运维知识汇总】第3天4:详解flanneld工作原理

flanneld实际上只是在宿主机上的路由表中添加了静态路由来完成通信

[root@hdss7-21 ~]# route -n

清除原有规划,实验VxLAN模型

[root@hdss7-21 ~]# supervisorctl stop flanneld-7-21flanneld-7-21: stopped[root@hdss7-21 ~]# supervisorctl statusetcd-server-7-21 RUNNING pid 12272, uptime 6 days, 21:27:13flanneld-7-21 STOPPED Jul 03 09:46 AMkube-apiserver-7-21 RUNNING pid 13277, uptime 5 days, 22:00:54kube-controller-manager-7-21 RUNNING pid 64267, uptime 1 day, 23:23:01kube-kubelet-7-21 RUNNING pid 17290, uptime 4 days, 15:21:44kube-proxy-7-21 RUNNING pid 55520, uptime 4 days, 12:07:09kube-scheduler-7-21 RUNNING pid 64261, uptime 1 day, 23:23:01[root@hdss7-21 ~]# ps -ef | grep flanneldroot 26835 1 0 07:08 ? 00:00:03 ./flanneld --public-ip=10.4.7.21 --etcd-endpoints=--etcd-keyfile=./cert/client-key.pem --etcd-certfile=./cert/client.pem --etcd-cafile=./cert/ca.pem --iface=ens33 --subnet-file=./subnet.env --healthz-port=2401root 66841 55814 0 09:46 pts/2 00:00:00 grep --color=auto flanneld[root@hdss7-21 ~]# kill -9 26835[root@hdss7-21 ~]# route -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 10.4.7.254 0.0.0.0 UG 100 0 0 ens3310.4.7.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33172.7.21.0 0.0.0.0 255.255.255.0 U 0 0 0 docker0172.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 -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 10.4.7.254 0.0.0.0 UG 100 0 0 ens3310.4.7.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33172.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/configPrevNode.Value: {"Network": "172.7.0.0/16", "Backend": {"Type": "host-gw"}}[root@hdss7-22 etcd]# ./etcdctl get /coreos.com/network/configError: 100: Key not found (/coreos.com/network/config) [23]

启动supervisord服务,并查看网卡信息

[root@hdss7-21 ~]# supervisorctl start flanneld-7-21flanneld-7-21: started[root@hdss7-21 ~]# supervisorctl status[root@hdss7-21 ~]# ifconfigdocker0: flags=4163 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 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 0ens33: flags=4163 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 inet6 fe80::9d0e:cf49:764f:a162 prefixlen 64 scopeid 0x20 inet6 fe80::758c:3945:4b43:ef1e prefixlen 64 scopeid 0x20 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 0flannel.1: flags=4163 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 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

直接路由模式

#智能模式,根据网络flanneld自行选择不同的模式

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规则:

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:【K8S运维知识汇总】第2天10:安装部署运算节点服务——kubelet
下一篇:丁道师:从代表行业到带动行业发展,何以看待东航物流价值?
相关文章

 发表评论

暂时没有评论,来抢沙发吧~