Docker 配置Flannel网络过程及原理
flannel 安装yum -y install flannelflannel 配置在etcd中创建变量etcdctl --endpoint http://10.132.47.70:2379 set /flannel/network/config '{"Network":"10.0.0.0/16","SubnetLen":24,"Backend":{"Type"
flannel 安装
yum -y install flannel
flannel 配置
在etcd中创建变量
etcdctl --endpoint http://10.132.47.70:2379 set /flannel/network/config '{"Network":"10.0.0.0/16","SubnetLen":24,"Backend":{"Type":"vxlan","VNI":0}}'
创建flannel日志目录
mkdir -p /var/log/k8s/flannel/
配置flannel
vi /etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS="http://10.132.47.70:2379,http://10.132.47.71:2379,http://10.132.47.72:2379"
FLANNEL_ETCD_PREFIX=“/flannel/network"
FLANNEL_OPTIONS="--logtostderr=false --log_dir=/var/log/k8s/flannel/ --etcd-endpoints=http://10.132.47.70:2379,http://10.132.47.71:2379,http://10.132.47.72:2379 --iface=eno16780032"
启动flannel
systemctl daemon-reload flanneld
systemctl restart flannel
systemctl enable flanneld
flannel启动过程解析
flannel服务需要先于docker启动。flannel服务启动时主要做了以下几步的工作:
- 从etcd中获取network的配置信息
- 划分subnet,并在etcd中进行注册
- 将子网信息记录到
/run/flannel/subnet.env
中
cat /run/flannel/subnet.env
FLANNEL_NETWORK=10.0.0.0/16 FLANNEL_SUBNET=10.0.53.1/24 FLANNEL_MTU=1450 FLANNEL_IPMASQ=false
- 之后将会有一个脚本将subnet.env转写成一个docker的环境变量文件
/run/flannel/docker
cat /run/flannel/docker
DOCKER_OPT_IPMASQ="--ip-masq=true" DOCKER_OPT_MTU="--mtu=1450" DOCKER_NETWORK_OPTIONS=" --bip=10.0.53.1/24 --ip-masq=true --mtu=1450 "
配置docker
sysetmctl show docker 将会发现 在安装flannel后自动生成配置
DropInPaths=/usr/lib/systemd/system/docker.service.d/flannel.conf
并引用/run/flannel/docker
故在docker的systemd文件中应用对应变量 DOCKER_NETWORK_OPTIONS 即可
vi /etc/systemd/system/docker.service.d/override.conf
[Service] ExecStart= ExecStart=/usr/bin/docker daemon --storage-driver=overlay --graph=/dcos/docker -H fd:// $DOCKER_NETWORK_OPTIONS
重新启动docker
systemctl daemon-reload
systemctl restart docker
测试
分别在两台节点上启动测试容器
docker run -d -it --name ip_test busybox
后网络互通,测试通过
references:
http://www.cnblogs.com/zhangeamon/p/6140074.html
更多推荐
所有评论(0)