一、下载Flannel
https://github.com/coreos/flannel/releases
二、配置flannel
解压并复制到指定目录
cp flanneld /opt/kubernetes/bin/
cp mk-docker-opts.sh /opt/kubernetes/bin/
三、systemd管理Flannel
vi /usr/lib/systemd/system/flanneld.service
[Unit]
Description=Flanneld overlay address etcd agent
After=network-online.target network.target
Before=docker.service
[Service]
Type=notify
EnvironmentFile=/opt/kubernetes/cfg/flanneld
ExecStart=/opt/kubernetes/bin/flanneld --ip-masq $FLANNEL_OPTIONS
ExecStartPost=/opt/kubernetes/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/subnet.env
Restart=on-failure
[Install]
WantedBy=multi-user.target
四、配置Flannel网络
cd /opt/kubernetes/ssl/
ETCDCTL_API=2 etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.112.134:2379,https://192.168.112.137:2379,https://192.168.112.138:2379" set /coreos.com/network/config '{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}'
查看配置信息
ETCDCTL_API=2 etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.112.134:2379,https://192.168.112.137:2379,https://192.168.112.138:2379" get /coreos.com/network/config '{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}'
注:flannel目前确实不能与etcdV3直接交互,只能用etcdv2。
解决方法:etcdctl 命令前加ETCDCTL_API=2
如:ETCDCTL_API=2 etcdctl -v
https://github.com/coreos/flannel/issues/1191
五、启动Flannel
systemctl daemon-reload
systemctl restart flanneld.service
systemctl enable flanneld.service
六、修改docker配置
vi /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
EnvironmentFile=/run/flannel/subnet.env
ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
重启docker
systemctl restart docker
查看网络
ip a
七、配置其他节点
同上
八、验证
节点之间互相ping对方docker 网关
192.168.112.137
ping 172.17.90.1
192.168.112.138
ping 172.17.95.1