一、部署网络插件
1、下载
wget https://github.com/coreos/flannel/releases/download/v0.13.0/flannel-v0.13.0-linux-amd64.tar.gz
2、安装部署
cd /opt/src mkdir -p /opt/flannel-v0.13.0/{bin,cfg,ssl,logs} tar -zxvf flannel-v0.13.0-linux-amd64.tar.gz -C /opt/flannel-v0.13.0/bin ln -s flannel-v0.13.0 flannel
3、拷贝证书
cd ~/TLS/k8s/ cp ca.pem server.pem server-key.pem /opt/flannel/ssl/
scp ca.pem server.pem server-key.pem root@192.168.112.111:/opt/flannel/ssl/
4、编辑环境变量env文件
vi /opt/flannel/cfg/subnet.env
FLANNEL_NETWORK=10.244.0.0/16 FLANNEL_SUBNET=10.244.110.1/24 FLANNEL_MTU=1500 FLANNEL_IPMASQ=false
5、编辑启动脚本
vi /opt/flannel/cfg/flanneld.sh
#!/bin/sh ./flanneld --public-ip=192.168.112.110 --etcd-endpoints=https://192.168.112.110:2379,https://192.168.112.111:2379,https://192.168.112.112:2379 \ --etcd-keyfile=/opt/flannel/ssl/etcd/server-key.pem --etcd-certfile=/opt/flannel/ssl/etcd/server.pem --etcd-cafile=/opt/flannel/ssl/etcd/ca.pem --iface=ens192 --subnet-file=./subnet.env --healthz-port=2401
chmod u+x /opt/flannel/cfg/flanneld.sh
6、在etcd中增加网络配置信息
ETCDCTL_API=3 /opt/etcd/bin/etcdctl --cacert=/opt/etcd/ssl/ca.pem --cert=/opt/etcd/ssl/server.pem --key=/opt/etcd/ssl/server-key.pem --endpoints="https://192.168.112.110:2379,https://192.168.112.111:2379,https://192.168.112.112:2379" put /coreos.com/network/config ‘{"Network": "172.7.0.0/16", "Backend": {"Type": "host-gw"}}‘
7、验证etcd中的网络配置信息
ETCDCTL_API=3 /opt/etcd/bin/etcdctl --cacert=/opt/etcd/ssl/ca.pem --cert=/opt/etcd/ssl/server.pem --key=/opt/etcd/ssl/server-key.pem --endpoints="https://192.168.112.110:2379,https://192.168.112.111:2379,https://192.168.112.112:2379" get /coreos.com/network/config