#flannel
#所有node都安装
#下载https://github.com/coreos/flannel/releases
#解压并把flanneld和mk-codker-opts.sh复制到/usr/bin
#配置服务
cp mk-docker-opts.sh flanneld /usr/bin/
cat << EOF > /usr/lib/systemd/system/flanneld.service
[Unit]
Description=flanneld overlay address etcd agent
After=network.target
Before=docker.service
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/flannel
ExecStart=/usr/bin/flanneld -etcd-endpoints=${FLANNEL_ETCD} $FLANNEL_OPTIONS
[Install]
RequiredBy=docker.service
WantedBy=multi-user.target
EOF
#创建文件,192.168.1.1:2379替换为etcd所在的IP与端口
cat << EOF > /etc/sysconfig/flannel
FLANNEL_ETCD="http://192.168.1.1:2379"
FLANNEL_ETCD_KEY="/coreos.com/network"
EOF
#ETCD上操作,设置网络段
etcdctl set /coreos.com/network/config '{ "Network": "10.1.0.0/16" }'
#启动flannel
systemctl start flanneld
systemctl enable flanneld
#设置docker网络
mk-docker-opts.sh -i
source /run/flannel/subnet.env
ifconfig docker0 ${FLANNEL_SUBNET}
#设置docker网络文件
mk-docker-opts.sh -d /etc/docker/docker_opts.env -c
#/usr/lib/systemd/system/docker.service增加
EnvironmentFile=/etc/docker/docker_opts.env
#docker应用flannel网络设置
systemctl daemon-reload
systemctl stop docker
#验证
ip addr
#etcd验证
etcdctl ls /coreos.com/network/subnets
#ping验证,通过etcd查看到的网段,IP替换为节点获取到的ip
ping 10.1.50.1
ping 10.1.46.1
#docker禁止了转发,导致创建的pod无法跨主机互通
iptables -P FORWARD ACCEPT