• 欢迎访问运维搬运工网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站。
  • 本站一年会员:100元 ,两年会员:180元 ,永久会员:380元
  • 这世界就是,一些人总在昼夜不停地运转,而另外一些人,起床就发现世界已经变了。
  • 本博客推广的是知识付费,用赞助的方式实现博客维护,不以赚钱为目的的博客

所有node节点配置flannel网络插件

安装flannel 插件

[root@k8s-master ~]# yum install flannel -y

[root@k8s-node1 ~]# yum install flannel -y

[root@k8s-node2 ~]# yum install flannel -y

配置

[root@k8s-master ~]# vim /etc/sysconfig/flanneld 

FLANNEL_ETCD_ENDPOINTS="http://10.0.0.11:2379"

FLANNEL_ETCD_PREFIX="/atomic.io/network"

创建key以及IP地址范围

[root@k8s-master ~]# etcdctl set /atomic.io/network/config '{"Network": "172.16.0.0/16"}'
{"Network": "172.16.0.0/16"}

启动

[root@k8s-master ~]# systemctl start flanneld.service 
[root@k8s-master ~]# systemctl enable flanneld.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.
Created symlink from /etc/systemd/system/docker.service.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.

重启docker服务

[root@k8s-master ~]# systemctl restart docker

查看网段是否一致

[root@k8s-master ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.16.38.1 netmask 255.255.255.0 broadcast 0.0.0.0
ether 02:42:40:1f:17:13 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 0 overruns 0 carrier 0 collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.11 netmask 255.255.255.0 broadcast 10.0.0.255
ether 00:16:3e:12:ac:ed txqueuelen 1000 (Ethernet)
RX packets 127546 bytes 134282603 (128.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 48627 bytes 35163099 (33.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.16.38.0 netmask 255.255.0.0 destination 172.16.38.0
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC)
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 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
loop txqueuelen 1000 (Local Loopback)
RX packets 696743 bytes 308166804 (293.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 696743 bytes 308166804 (293.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

配置node1和node2

[root@k8s-node1 ~]# vim /etc/sysconfig/flanneld 

FLANNEL_ETCD_ENDPOINTS="http://10.0.0.11:2379"

启动

[root@k8s-node1 ~]# systemctl start flanneld.service
[root@k8s-node1 ~]# systemctl enable flanneld.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.
Created symlink from /etc/systemd/system/docker.service.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.
[root@k8s-node1 ~]# systemctl restart docker

node2配置

[root@k8s-node2 ~]# vim /etc/sysconfig/flanneld 

FLANNEL_ETCD_ENDPOINTS="http://10.0.0.11:2379"

启动服务

[root@k8s-node2 ~]# systemctl start flanneld.service
[root@k8s-node2 ~]# systemctl enable flanneld.service
Created symlink from /etc/systemd/system/multi-user.target.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.
Created symlink from /etc/systemd/system/docker.service.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.
[root@k8s-node2 ~]# systemctl restart docker

测试宿主机与容器之间等互通性

下载一个测试镜像

[root@k8s-node1 ~]# docker pull busybox
Using default tag: latest
Trying to pull repository docker.io/library/busybox ... 
latest: Pulling from docker.io/library/busybox
ee153a04d683: Pull complete 
Digest: sha256:9f1003c480699be56815db0f8146ad2e22efea85129b5b5983d0e0fb52d9ab70
Status: Downloaded newer image for docker.io/busybox:latest

所有节点都进入这个容器

master节点

[root@k8s-master ~]# docker run -it busybox
/ # 
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:10:26:02 
inet addr:172.16.38.2 Bcast:0.0.0.0 Mask:255.255.255.0
inet6 addr: fe80::42:acff:fe10:2602/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1472 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0 
RX bytes:0 (0.0 B) TX bytes:516 (516.0 B)

lo Link encap:Local Loopback 
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

node1节点

[root@k8s-node1 ~]# docker run -it busybox
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:10:27:02 
inet addr:172.16.39.2 Bcast:0.0.0.0 Mask:255.255.255.0
inet6 addr: fe80::42:acff:fe10:2702/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1472 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0 
RX bytes:0 (0.0 B) TX bytes:656 (656.0 B)

lo Link encap:Local Loopback 
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

node2节点

[root@k8s-node2 ~]# docker run -it busybox
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:10:35:02 
inet addr:172.16.53.2 Bcast:0.0.0.0 Mask:255.255.255.0
inet6 addr: fe80::42:acff:fe10:3502/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1472 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0 
RX bytes:0 (0.0 B) TX bytes:656 (656.0 B)

lo Link encap:Local Loopback 
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

测试能不能ping通

 # ping 172.16.39.2
PING 172.16.39.2 (172.16.39.2): 56 data bytes

依旧不通,是因为iptables得调整

[root@k8s-master ~]# iptables -P FORWARD ACCEPT

再次测试能不能通

/ # ping 172.16.39.2
PING 172.16.39.2 (172.16.39.2): 56 data bytes
64 bytes from 172.16.39.2: seq=0 ttl=60 time=0.798 ms
64 bytes from 172.16.39.2: seq=1 ttl=60 time=1.679 ms
64 bytes from 172.16.39.2: seq=2 ttl=60 time=1.468 ms

把这个防火墙配置加入到docker配置文件中,省得以后重启机器出问题。(所有节点都添加)

[root@k8s-master ~]# vim /usr/lib/systemd/system/docker.service

加一行

ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT

使其生效

[root@k8s-master ~]# systemctl daemon-reload

运维搬运工 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:所有node节点配置flannel网络插件
喜欢 (0)
[扫描二维码]
分享 (0)
大自然搬运工
关于作者:
不是路不平,而是你不行。到底行不行,看你停不停。只要你不停,早晚都能行。
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址