包:flannel-v0.10.0-linux-amd64.tar.gz,具体版本自己网上可以选择下载:https://github.com/coreos/flannel/releases/download/v0.10.0/flannel-v0.10.0-linux-amd64.tar.gz
将解压后得到的可执行文件放入我们之定义的路径下面
cp flanneld mk-docker-opts.sh /opt/kubernetes/bin/
配置配置文件:
#写flanneld配置文件 cat <<EOF >/opt/kubernetes/cfg/flanneld FLANNEL_OPTIONS="--etcd-endpoints=https://10.50.182.65:2379,https://10.50.182.66:2379,https://10.50.182.67:2379 -etcd-cafile=/opt/kubernetes/ssl/ca.pem -etcd-certfile=/opt/kubernetes/ssl/server.pem -etcd-keyfile=/opt/kubernetes/ssl/server-key.pem" EOF #写入 flanneld系统配置文件 cat <<EOF >/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 EOF #写入分配的子网段到etcd,供flanneld使用 cd /opt/kubernetes/ssl /opt/kubernetes/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://10.50.182.65:2379,https://10.50.182.66:2379,https://10.50.182.67:2379" set /coreos.com/network/config '{ "Network": "10.147.224.0/20", "Backend": {"Type": "vxlan"}}'
启动Flannel,日志在/var/log/messages:
systemctl enable flanneld
systemctl start flanneld
查看flanneld分配的网络:
cat /run/flannel/subnet.env
编辑docker系统配置文件:
cat <<EOF >/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 EOF systemctl daemon-reload systemctl restart docker
查看ifconfig 中 会出现一个flannel 网络,并且flannel和docker0 网络段会相同
设置完成后将配置文件分发到master02和master03
scp -P 10022 jyapp@10.50.182.65:/opt/kubernetes/cfg/flanneld /opt/kubernetes/cfg/ scp -P 10022 jyapp@10.50.182.65:/usr/lib/systemd/system/flanneld.service /usr/lib/systemd/system/ scp -P 10022 jyapp@10.50.182.65:/opt/kubernetes/bin/flanneld /opt/kubernetes/bin/
master02和maser03上修改成和master01一致
systemctl daemon-reload
systemctl enable flanneld
systemctl start flanneld
systemctl restart docker
查看ifconfig 是否有flanneld,docker0网络是否和flanneld一致,
在master上ping node02上的docker0网关,如果能通的话证明Ok