Kubernetes配置flannel网络

操作环境

网络拓扑图

操作步骤

配置k8s-master

1.在k8s-master节点上创建flannel网络

[root@k8s-master yaml]# etcdctl mk /atomic.io/network/config '{"Network": "172.17.0.0/16"}'

2.配置flannel

  1. [root@k8s-master yaml]# vi /etc/sysconfig/flanneld

  2. # Flanneld configuration options

  3.  
  4. # etcd url location. Point this to the server where etcd runs

  5. FLANNEL_ETCD_ENDPOINTS="http://10.10.200.224:2379"

  6.  
  7. # etcd config key. This is the configuration key that flannel queries

  8. # For address range assignment

  9. FLANNEL_ETCD_PREFIX="/atomic.io/network"

  10. #FLANNEL_ETCD_PREFIX="/k8s/network"

  11. # Any additional options that you want to pass

  12. #FLANNEL_OPTIONS="ens192"

 
  1. [root@k8s-master yaml]# vi /usr/lib/systemd/system/flanneld.service

  2. [Unit]

  3. Description=Flanneld overlay address etcd agent

  4. After=network.target

  5. After=network-online.target

  6. Wants=network-online.target

  7. After=etcd.service

  8. Before=docker.service

  9. [Service]

  10. Type=notify

  11. EnvironmentFile=/etc/sysconfig/flanneld

  12. EnvironmentFile=-/etc/sysconfig/docker-network

  13. #ExecStart=/usr/bin/flanneld-start $FLANNEL_OPTIONS

  14. ExecStart=/usr/bin/flanneld -etcd-endpoints=http://10.10.200.224:2379

  15. ExecStartPost=/usr/libexec/flannel/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/docker

  16. Restart=on-failure

  17. [Install]

  18. WantedBy=multi-user.target

  19. RequiredBy=docker.service

3.启动flannel

[root@k8s-master ~]# systemctl start flanneld.service 

  在启动flannel,通过ifconfig可以查看到flannel0

  1. [root@k8s-master ~]# ifconfig

  2. ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

  3. inet 10.10.200.224 netmask 255.255.255.0 broadcast 10.10.200.255

  4. inet6 fe80::ec55:e4e8:4be:93bb prefixlen 64 scopeid 0x20<link>

  5. ether 00:0c:29:18:3f:c3 txqueuelen 1000 (Ethernet)

  6. RX packets 147042 bytes 44436790 (42.3 MiB)

  7. RX errors 0 dropped 30 overruns 0 frame 0

  8. TX packets 148062 bytes 33065150 (31.5 MiB)

  9. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  10. flannel0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1472

  11. inet 172.17.30.0 netmask 255.255.0.0 destination 172.17.30.0

  12. inet6 fe80::3908:159:b907:1624 prefixlen 64 scopeid 0x20<link>

  13. unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC)

  14. RX packets 1321 bytes 1737235 (1.6 MiB)

  15. RX errors 0 dropped 0 overruns 0 frame 0

  16. TX packets 630 bytes 58891 (57.5 KiB)

  17. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  18. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

  19. inet 127.0.0.1 netmask 255.0.0.0

  20. inet6 ::1 prefixlen 128 scopeid 0x10<host>

  21. loop txqueuelen 1 (Local Loopback)

  22. RX packets 64441 bytes 28164690 (26.8 MiB)

  23. RX errors 0 dropped 0 overruns 0 frame 0

  24. TX packets 64441 bytes 28164690 (26.8 MiB)

  25. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

配置k8s-node

1.2个节点flannel的方法相同,配置flannel

  1. [root@k8s-node1 ~]# vi /etc/sysconfig/flanneld

  2. # Flanneld configuration options

  3.  
  4. # etcd url location. Point this to the server where etcd runs

  5. FLANNEL_ETCD_ENDPOINTS="http://10.10.200.224:2379"

  6.  
  7. # etcd config key. This is the configuration key that flannel queries

  8. # For address range assignment

  9. FLANNEL_ETCD_PREFIX="/atomic.io/network"

  10. #FLANNEL_ETCD_PREFIX="/k8s/network"

  11. # Any additional options that you want to pass

  12. #FLANNEL_OPTIONS="ens192"

  13. [root@k8s-master yaml]# vi /usr/lib/systemd/system/flanneld.service

  14. [Unit]

  15. Description=Flanneld overlay address etcd agent

  16. After=network.target

  17. After=network-online.target

  18. Wants=network-online.target

  19. After=etcd.service

  20. Before=docker.service

  21.  
  22. [Service]

  23. Type=notify

  24. EnvironmentFile=/etc/sysconfig/flanneld

  25. EnvironmentFile=-/etc/sysconfig/docker-network

  26. #ExecStart=/usr/bin/flanneld-start $FLANNEL_OPTIONS

  27. ExecStart=/usr/bin/flanneld -etcd-endpoints=http://10.10.200.224:2379

  28. ExecStartPost=/usr/libexec/flannel/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/docker

  29. Restart=on-failure

  30.  
  31. [Install]

  32. WantedBy=multi-user.target

  33. RequiredBy=docker.service

2.启动flannel

[root@k8s-node1 ~]# systemctl start flanneld.service

3.启动flannel后,可以通过ifconfig查看到flannel0

  1. [root@k8s-node1 ~]# ifconfig

  2. docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1472

  3. inet 172.17.23.1 netmask 255.255.255.0 broadcast 0.0.0.0

  4. inet6 fe80::42:a5ff:fef4:9795 prefixlen 64 scopeid 0x20<link>

  5. ether 02:42:a5:f4:97:95 txqueuelen 0 (Ethernet)

  6. RX packets 1430 bytes 1851730 (1.7 MiB)

  7. RX errors 0 dropped 0 overruns 0 frame 0

  8. TX packets 1490 bytes 1290056 (1.2 MiB)

  9. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  10.  
  11. ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

  12. inet 10.10.200.229 netmask 255.255.255.0 broadcast 10.10.200.255

  13. inet6 fe80::5834:2493:e9ef:3b95 prefixlen 64 scopeid 0x20<link>

  14. ether 00:0c:29:f6:c6:42 txqueuelen 1000 (Ethernet)

  15. RX packets 264090 bytes 41537991 (39.6 MiB)

  16. RX errors 0 dropped 19 overruns 0 frame 0

  17. TX packets 251049 bytes 64982214 (61.9 MiB)

  18. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  19.  
  20. flannel0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1472

  21. inet 172.17.23.0 netmask 255.255.0.0 destination 172.17.23.0

  22. inet6 fe80::da8b:b01f:3f46:3352 prefixlen 64 scopeid 0x20<link>

  23. unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC)

  24. RX packets 616 bytes 58064 (56.7 KiB)

  25. RX errors 0 dropped 0 overruns 0 frame 0

  26. TX packets 1315 bytes 1736045 (1.6 MiB)

  27. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  28.  
  29. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

  30. inet 127.0.0.1 netmask 255.0.0.0

  31. inet6 ::1 prefixlen 128 scopeid 0x10<host>

  32. loop txqueuelen 1 (Local Loopback)

  33. RX packets 438 bytes 23836 (23.2 KiB)

  34. RX errors 0 dropped 0 overruns 0 frame 0

  35. TX packets 438 bytes 23836 (23.2 KiB)

  36. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

4.设置docker0的ip地址

[root@k8s-node1 ~]# ifconfig docker0 172.17.23.1

5.节点2参照上述配置进行设置即可

通过上述就完成了配置flannel

参考文章

https://www.kubernetes.org.cn/3682.html

猜你喜欢

转载自blog.csdn.net/bbwangj/article/details/82669226
今日推荐