Kubernetes配置flannel网络

2019-06-12 16:27:44 浏览数 (1)

操作环境

网络拓扑图

操作步骤

配置k8s-master

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

代码语言:javascript复制
[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. # etcd url location. Point this to the server where etcd runs
  4. FLANNEL_ETCD_ENDPOINTS="http://10.10.200.224:2379"
  5. # etcd config key. This is the configuration key that flannel queries
  6. # For address range assignment
  7. FLANNEL_ETCD_PREFIX="/atomic.io/network"
  8. #FLANNEL_ETCD_PREFIX="/k8s/network"
  9. # Any additional options that you want to pass
  10. #FLANNEL_OPTIONS="ens192"
代码语言:javascript复制
  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

代码语言:javascript复制
[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. # etcd url location. Point this to the server where etcd runs
  4. FLANNEL_ETCD_ENDPOINTS="http://10.10.200.224:2379"
  5. # etcd config key. This is the configuration key that flannel queries
  6. # For address range assignment
  7. FLANNEL_ETCD_PREFIX="/atomic.io/network"
  8. #FLANNEL_ETCD_PREFIX="/k8s/network"
  9. # Any additional options that you want to pass
  10. #FLANNEL_OPTIONS="ens192"
  11. [root@k8s-master yaml]# vi /usr/lib/systemd/system/flanneld.service
  12. [Unit]
  13. Description=Flanneld overlay address etcd agent
  14. After=network.target
  15. After=network-online.target
  16. Wants=network-online.target
  17. After=etcd.service
  18. Before=docker.service
  19. [Service]
  20. Type=notify
  21. EnvironmentFile=/etc/sysconfig/flanneld
  22. EnvironmentFile=-/etc/sysconfig/docker-network
  23. #ExecStart=/usr/bin/flanneld-start $FLANNEL_OPTIONS
  24. ExecStart=/usr/bin/flanneld -etcd-endpoints=http://10.10.200.224:2379
  25. ExecStartPost=/usr/libexec/flannel/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/docker
  26. Restart=on-failure
  27. [Install]
  28. WantedBy=multi-user.target
  29. RequiredBy=docker.service

2.启动flannel

代码语言:javascript复制
[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. ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  11. inet 10.10.200.229 netmask 255.255.255.0 broadcast 10.10.200.255
  12. inet6 fe80::5834:2493:e9ef:3b95 prefixlen 64 scopeid 0x20<link>
  13. ether 00:0c:29:f6:c6:42 txqueuelen 1000 (Ethernet)
  14. RX packets 264090 bytes 41537991 (39.6 MiB)
  15. RX errors 0 dropped 19 overruns 0 frame 0
  16. TX packets 251049 bytes 64982214 (61.9 MiB)
  17. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  18. flannel0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1472
  19. inet 172.17.23.0 netmask 255.255.0.0 destination 172.17.23.0
  20. inet6 fe80::da8b:b01f:3f46:3352 prefixlen 64 scopeid 0x20<link>
  21. unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC)
  22. RX packets 616 bytes 58064 (56.7 KiB)
  23. RX errors 0 dropped 0 overruns 0 frame 0
  24. TX packets 1315 bytes 1736045 (1.6 MiB)
  25. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  26. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  27. inet 127.0.0.1 netmask 255.0.0.0
  28. inet6 ::1 prefixlen 128 scopeid 0x10<host>
  29. loop txqueuelen 1 (Local Loopback)
  30. RX packets 438 bytes 23836 (23.2 KiB)
  31. RX errors 0 dropped 0 overruns 0 frame 0
  32. TX packets 438 bytes 23836 (23.2 KiB)
  33. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

4.设置docker0的ip地址

代码语言:javascript复制
[root@k8s-node1 ~]# ifconfig docker0 172.17.23.1

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

通过上述就完成了配置flannel

参考文章

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

0 人点赞