部署Flannel网络

部署Flannel网络

部署flannel网络需要执行以下步骤:

1)写入分配的子网段到etcd,供flanneld使用
2)下载二进制包
3)配置Flannel
4)systemd管理Flannel
5)配置Docker启动指定子网段
6)启动

第一步:下载flannel二进制包

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

第二步:解压flannel二进制包并且复制到其他节点

//解压二进制文件
tar -zxvf flannel-v0.9.1-linux-amd64.tar.gz 
//将可执行文件flanneld mk-docker-opts.sh复制发送到其他节点
scp flanneld mk-docker-opts.sh  root@172.16.163.130:/opt/kubernetes/bin/

第三步:写入分配的子网段到etcd,供flanneld使用

/opt/kubernetes/bin/etcdctl \
--ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem \
--endpoints="https://172.16.163.131:2379,https://172.16.163.130:2379,https://172.16.163.129:2379" \
set /coreos.com/network/config '{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}'

第四步:编写flanneld配置文件

NNEL_OPTIONS="--etcd-endpoints=https://172.16.163.131:2379,https://172.16.163.130:2379,https://172.16.163.129:2379 -etcd-cafile=/opt/kubernetes/ssl/ca.pem -etcd-certfile=/opt/kubernetes/ssl/server.pem -etcd-keyfile=/opt/kubernetes/ssl/server-key.pem"

第五步:编写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

第六步:docker.service配置文件

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.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

以上配置好了之后,需要将flanneld配置文件,flanneld.service文件,docker.service文件,复制到其他节点。

第七步:启动服务

systemctl daemon-reload
systemctl start flanneld
systemctl enable flanneld
systemctl restart docker

最后配置结果截图

posted @ 2019-09-07 23:39  jason小蜗牛  阅读(1726)  评论(0编辑  收藏  举报