赞
踩
网络拓扑图
操作步骤
1.在k8s-master节点上创建flannel网络
[root@k8s-master yaml]# etcdctl mk /atomic.io/network/config '{"Network": "172.17.0.0/16"}'
2.配置flannel
[root@k8s-master yaml]# vi /etc/sysconfig/flanneld
# Flanneld configuration options
# etcd url location. Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS="http://10.10.200.224:2379"
# etcd config key. This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX="/atomic.io/network"
#FLANNEL_ETCD_PREFIX="/k8s/network"
# Any additional options that you want to pass
#FLANNEL_OPTIONS="ens192"
[root@k8s-master yaml]# vi /usr/lib/systemd/system/flanneld.service
[Unit]
Description=Flanneld overlay address etcd agent
After=network.target
After=network-online.target
Wants=network-online.target
After=etcd.service
Before=docker.service
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/flanneld
EnvironmentFile=-/etc/sysconfig/docker-network
#ExecStart=/usr/bin/flanneld-start $FLANNEL_OPTIONS
ExecStart=/usr/bin/flanneld -etcd-endpoints=http://10.10.200.224:2379
ExecStartPost=/usr/libexec/flannel/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/docker
Restart=on-failure
[Install]
WantedBy=multi-user.target
RequiredBy=docker.service
3.启动flannel
[root@k8s-master ~]# systemctl start flanneld.service
在启动flannel,通过ifconfig可以查看到flannel0
[root@k8s-master ~]# ifconfig
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.10.200.224 netmask 255.255.255.0 broadcast 10.10.200.255
inet6 fe80::ec55:e4e8:4be:93bb prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:18:3f:c3 txqueuelen 1000 (Ethernet)
RX packets 147042 bytes 44436790 (42.3 MiB)
RX errors 0 dropped 30 overruns 0 frame 0
TX packets 148062 bytes 33065150 (31.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
flannel0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1472
inet 172.17.30.0 netmask 255.255.0.0 destination 172.17.30.0
inet6 fe80::3908:159:b907:1624 prefixlen 64 scopeid 0x20<link>
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC)
RX packets 1321 bytes 1737235 (1.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 630 bytes 58891 (57.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 64441 bytes 28164690 (26.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 64441 bytes 28164690 (26.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
1.2个节点flannel的方法相同,配置flannel
[root@k8s-node1 ~]# vi /etc/sysconfig/flanneld
# Flanneld configuration options
# etcd url location. Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS="http://10.10.200.224:2379"
# etcd config key. This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX="/atomic.io/network"
#FLANNEL_ETCD_PREFIX="/k8s/network"
# Any additional options that you want to pass
#FLANNEL_OPTIONS="ens192"
[root@k8s-master yaml]# vi /usr/lib/systemd/system/flanneld.service
[Unit]
Description=Flanneld overlay address etcd agent
After=network.target
After=network-online.target
Wants=network-online.target
After=etcd.service
Before=docker.service
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/flanneld
EnvironmentFile=-/etc/sysconfig/docker-network
#ExecStart=/usr/bin/flanneld-start $FLANNEL_OPTIONS
ExecStart=/usr/bin/flanneld -etcd-endpoints=http://10.10.200.224:2379
ExecStartPost=/usr/libexec/flannel/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/docker
Restart=on-failure
[Install]
WantedBy=multi-user.target
RequiredBy=docker.service
2.启动flannel
[root@k8s-node1 ~]# systemctl start flanneld.service
3.启动flannel后,可以通过ifconfig查看到flannel0
[root@k8s-node1 ~]# ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1472
inet 172.17.23.1 netmask 255.255.255.0 broadcast 0.0.0.0
inet6 fe80::42:a5ff:fef4:9795 prefixlen 64 scopeid 0x20<link>
ether 02:42:a5:f4:97:95 txqueuelen 0 (Ethernet)
RX packets 1430 bytes 1851730 (1.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1490 bytes 1290056 (1.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.10.200.229 netmask 255.255.255.0 broadcast 10.10.200.255
inet6 fe80::5834:2493:e9ef:3b95 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:f6:c6:42 txqueuelen 1000 (Ethernet)
RX packets 264090 bytes 41537991 (39.6 MiB)
RX errors 0 dropped 19 overruns 0 frame 0
TX packets 251049 bytes 64982214 (61.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
flannel0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1472
inet 172.17.23.0 netmask 255.255.0.0 destination 172.17.23.0
inet6 fe80::da8b:b01f:3f46:3352 prefixlen 64 scopeid 0x20<link>
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC)
RX packets 616 bytes 58064 (56.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1315 bytes 1736045 (1.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 438 bytes 23836 (23.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 438 bytes 23836 (23.2 KiB)
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
参考文章
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。