5、flannel

cp flanneld /usr/bin/
chmod 755 /usr/bin/flanneld
mkdir -p /app/flannel/conf/

vi /usr/lib/systemd/system/flanneld.service
[Unit]
Description=flanneld overlay address etcd agent
After=network.target
Before=docker.service
[Service]
Type=notify
EnvironmentFile=/app/flannel/conf/flanneld
ExecStart=/usr/bin/flanneld -etcd-endpoints=${FLANNEL_ETCD} ${FLANNEL_OPTIONS}
[Install]
RequiredBy=docker.service
WantedBy=multi-user.target

vi /app/flannel/conf/flanneld
FLANNEL_ETCD="http://192.168.254.53:2379" #此处输入集群master地址
FLANNEL_ETCD_KEY="/coreos.com/network"
FLANNEL_OPTIONS="-iface=ens32" #此处写网卡

以下两句只有master执行
etcdctl set /coreos.com/network/config '{"Network":"10.0.0.0/16","SubnetMin":"10.0.1.0","SubnetMax":"10.0.20.0"}'
etcdctl get /coreos.com/network/config

systemctl daemon-reload
systemctl enable flanneld.service
systemctl start flanneld.service
systemctl status flanneld.service

./mk-docker-opts.sh -i
cat /run/flannel/subnet.env
cat /run/docker_opts.env
source /run/flannel/subnet.env

vim /run/flannel/subnet.env
把--ip-masq=false 改成 --ip-masq=true

vi /usr/lib/systemd/system/docker.service加入
EnvironmentFile=/run/flannel/subnet.env
两个参数:--bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU}
ExecStart=/usr/bin/dockerd --bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU}
K8S 1.9.0二进制包部署(四)

systemctl daemon-reload
systemctl restart docker
etcdctl ls /coreos.com/network/subnets
etcdctl get /coreos.com/network/subnets/10.0.8.0-24

flannel安装成功后 查看下docker 是否在flannel所在网段内。
K8S 1.9.0二进制包部署(四)
创建 docker run -itd bbox1 busybox 测试ping 1、从容器到跨主机 2、从主机到容器 3、容器跨主机容器
容器内互相不能ping通,原因访问策略问题
所有节点执行
iptables -P FORWARD ACCEPT

参考http://blog.csdn.net/liukuan73/article/details/54897594
参考https://www.hi-linux.com/posts/30481.html