flannel三种模型安装部署详解
yht_1990关注[2020-10-04 12:13:47](javascript:😉
架构图
kubernetes设计了网络模型,但却将它的实现交给了网络插件,CNI网络插件最主要的功能主是实现pod资源能够跨宿主机进行通信
常见的CNI网络插件:
- Flannel
- Calico
- Canal
- Contiv
- OpenContrail
- NSX-T
- Kube-router
Flannel三种模型:
- host-gw
- VxLan
- Directrouting
1.1 host-gw模型
host-gw模型即网关模式,在服务器直接添加一条静态路由即可,效率高,各节点必须在同一网段
10.4.7.21通过172.7.22.0这条静态路由连接10.4.7.22这台主机再连接172.7.21网段,反之亦是
/opt/etcd/etcdctl set /coreos.com/network/config '{"Network": "172.7.0.0/16", "Backend": {"Type": "host-gw"}}'
/opt/etcd/etcdctl set /coreos.com/network/config # 查看
/opt/etcd/etcdctl rm /coreos.com/network/config # 删除
1.2 VxLAN模型
在不同网段,可以用VxLAN模式,主机A会生成一个flannel.1网卡,通过封装头从flannel.1网卡出去,通过flanne隧道传出,从flannel.1网卡传入拆包,到达目标主机网卡到指向的静态路由,效率低
/opt/etcd/etcdctl set /coreos.com/network/config '{"Network": "172.7.0.0/16", "Backend": {"Type": "VxLAN"}}'
1.3 Directrouting模型
- 直接路由模式,结合了VxLAN和host-gw模型
- 自动识别服务器,如果同网段,则使用host-gw模型,如果不同网段则使用VxLAN模型
/opt/etcd/etcdctl set /coreos.com/network/config '{"Network": "172.7.0.0/16", "Backend": {"Type": "VxLAN","Directrouting": true}}'
1.4 Flannel部署
1.4.1 集群规划
主机名 | IP | 角色 | 节点 |
---|---|---|---|
hdss21-host.com | 10.4.7.21 | Flannel | Node |
hdss22-host.com | 10.4.4.22 | Flannel | Node |
1.4.2 下载解压
在hdss21-host.com操作,hdss22-host.com操作类似
下载链接:https://github.com/coreos/flannel/releases
cd /opt/src
rz ==> flannel-v0.12.0-linux-amd64.tar.gz
mkdir /opt/flanneld-v0.12.0
tar xf flannel-v0.12.0-linux-amd64.tar.gz -C /opt/flanneld-v0.12.0
ln -s /opt/flanneld-v0.12.0 /opt/flannel
1.4.3 创建配置
cat > /opt/flannel/subnet.env <<'eof'
FLANNEL_NETWORK=172.7.0.0/16
FLANNEL_SUBNET=172.7.21.1/24
FLANNEL_MTU=1500
FLANNEL_IPMASQ=false
eof
不同地方
172.4.7.21 配置 FLANNEL_SUBNET=172.7.21.1/24
172.4.7.22 配置 FLANNEL_SUBNET=172.7.22.1/24
1.4.4 拷贝证书
mkdir /opt/flannel/certs
scp hdss7-200:/opt/certs/ca.pem /opt/flannel/certs/
scp hdss7-200:/opt/certs/client.pem /opt/flannel/certs/
scp hdss7-200:/opt/certs/client-key.pem /opt/flannel/certs/
1.4.5 创建启动脚本
cat > /opt/flannel/flanneld.sh <<'eof'
#!/bin/sh
./flanneld \
--public-ip=10.4.7.21 \
--etcd-endpoints=https://10.4.7.12:2379,https://10.