k8s-部署-15-CNI网络-flannel

k8s-部署-15-CNI网络-flannel

1、常见的CNI网络插件介绍

  • Flannel
  • Calico
  • Cancl
  • OpenContrail
  • NSX-T
  • Kube-router

2、flannel下载地址:

2.1、github上的下载地址

https://github.com/coreos/flannel/releases

2.3、具体的下载方法

wget https://github.com/coreos/flannel/releases/download/v0.11.0/flannel-v0.11.0-linux-amd64.tar.gz

3、flannel安装

复制代码
# 1、创建相应的目录,并将压缩包解压
~]# cd /opt/src/
src]# mkdir /opt/flannel-v0.11.0
src]# tar xf flannel-v0.11.0-linux-amd64.tar.gz -C /opt/flannel-v0.11.0/
src]# ln -s /opt/flannel-v0.11.0/ /opt/flannel

# 2、拷贝证书
~]# cd /opt/flannel && mkdir cert
cert]# scp hdss7-200:/opt/certs/ca.pem .
cert]# scp hdss7-200:/opt/certs/client.pem . 
cert]# scp hdss7-200:/opt/certs/client-key.pem .

# 3、修改subnet.env
[root@hdss7-11 flannel]# vi subnet.env
FLANNEL_NETWORK=172.7.0.0/16
FLANNEL_SUBNET=172.7.21.1/24
FLANNEL_MTU=1500
FLANNEL_IPMASQ=false

# 4、创建启动脚本
[root@hdss7-11 flannel]# vi flanneld.sh 
#!/bin/sh
./flanneld \
  --public-ip=10.4.7.21 \
  --etcd-endpoints=https://10.4.7.12:2379,https://10.4.7.21:2379,https://10.4.7.22:2379 \
  --etcd-keyfile=./cert/client-key.pem \
  --etcd-certfile=./cert/client.pem \
  --etcd-cafile=./cert/ca.pem \
  --iface=ens33 \
  --subnet-file=./subnet.env \
  --healthz-port=2401

# 5、创建相应的目录并加可执行权限
[root@hdss7-11 flannel]# chmod +x flanneld.sh 

[root@hdss7-11 flannel]# mkdir -p /data/logs/flanneld
复制代码

 4、在Etcd中,增加host-gw模型

复制代码
# 1、切换到etcd所在的服务器
~]# cd /opt/etcd
etcd]# ./etcdctl set /coreos.com/network/config '{"Network": "172.7.0.0/16", "Backend": {"Type": "host-gw"}}'

# 2、查看集群的状态
etcd]# ./etcdctl member list

# 3、查看flanneld网络
etcd]# ./etcdctl get /coreos.com/network/config
复制代码

 

5、创建守护进程脚本

复制代码
# 1、创建守护进程脚本
flannel]# vi /etc/supervisord.d/flannel.ini
[program:flanneld-7-21]
command=/opt/flannel/flanneld.sh                             ; the program (relative uses PATH, can take args)
numprocs=1                                                   ; number of processes copies to start (def 1)
directory=/opt/flannel                                       ; directory to cwd to before exec (def no cwd)
autostart=true                                               ; start at supervisord start (default: true)
autorestart=true                                             ; retstart at unexpected quit (default: true)
startsecs=30                                                 ; number of secs prog must stay running (def. 1)
startretries=3                                               ; max # of serial start failures (default 3)
exitcodes=0,2                                                ; 'expected' exit codes for process (default 0,2)
stopsignal=QUIT                                              ; signal used to kill process (default TERM)
stopwaitsecs=10                                              ; max num secs to wait b4 SIGKILL (default 10)
user=root                                                    ; setuid to this UNIX account to run the program
redirect_stderr=true                                         ; redirect proc stderr to stdout (default false)
stdout_logfile=/data/logs/flanneld/flanneld.stdout.log       ; stderr log path, NONE for none; default AUTO
stdout_logfile_maxbytes=64MB                                 ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=4                                     ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB                                  ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false                                  ; emit events on stdout writes (default false)

# 2、启动服务
flannel]# supervisorctl update

# 3、查看服务启动状态
flannel]# supervisorctl status
复制代码

 

6、flannel工具原理介绍

复制代码
# 1、查看路由
flannel]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.16.1    0.0.0.0         UG    100    0        0 enp2s0
172.7.11.0      192.168.16.11   255.255.255.0   UG    0      0        0 enp2s0
172.7.12.0      0.0.0.0         255.255.255.0   U     0      0        0 docker0
172.7.13.0      192.168.16.13   255.255.255.0   UG    0      0        0 enp2s0
172.7.14.0      192.168.16.14   255.255.255.0   UG    0      0        0 enp2s0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-7957b5310092
192.168.16.0    0.0.0.0         255.255.255.0   U     100    0        0 enp2s0
复制代码

 

总结:

  • flannel原理就是:给宿主机添加一个静态路由,到达pod ip
  • flannel的host-gw模型,所有node ip必须在同一个物理网管设备下才能使用

7、flannel的其他网络模型介绍

7.1、Vxlan模型

# 1、Vxlan模型
'{"Network": "172.7.0.0/16", "Backend": {"Type": "VxLAN"}}'

# 2、具体配置
etcd]# ./etcdctl set /coreos.com/network/config '{"Network": "172.7.0.0/16", "Backend": {"Type": "VxLAN"}}'

 

7.2、直接路由模型

# 1、直接路由模型配置
'{"Network": "172.7.0.0/16", "Backend": {"Type": "VxLAN","Directrouting": true}}'

 7.3、更改flanneld的网络模型

复制代码
# 1、停止flannel服务
flannel]# supervisorctl stop flanneld-7-11
flannel]# ps aux | grep flanneld 
flannel]# kill  PID

#2、删除之前配置的路由
flannel]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.16.1    0.0.0.0         UG    100    0        0 enp2s0
172.7.11.0      192.168.16.11   255.255.255.0   UG    0      0        0 enp2s0
172.7.12.0      0.0.0.0         255.255.255.0   U     0      0        0 docker0
172.7.13.0      192.168.16.13   255.255.255.0   UG    0      0        0 enp2s0
172.7.14.0      192.168.16.14   255.255.255.0   UG    0      0        0 enp2s0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-7957b5310092
192.168.16.0    0.0.0.0         255.255.255.0   U     100    0        0 enp2s0

flannel]# route del -net 172.7.12.0/24 gw 192.168.16.12

flannel]# route del -net 172.7.11.0/24 gw 192.168.16.11

flannel]# ./etcdctl rm /coreos.com/network/config

# 2、配置新的网络模型
etcd]# ./etcdctl set /coreos.com/network/config '{"Network": "172.7.0.0/16", "Backend": {"Type": "VxLAN"}}'

# 3、启动服务
flannel]# supervisorctl start flanneld-7-11
复制代码

 

8、备注 

  • 直接路由模型:
  • vxaln模型:当node不在同一个物理网关下
  • host-gw模型:在同一个网关下

 

posted @   AlexMa  阅读(184)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示