Flannel网络配置

Flannel工作原理

Flannel是一种覆盖网络(overlay network),将TCP数据包装在另一种网络包里面进行路由转发和通讯,转发方式:UDP 、VxLAN 、GCE、AWS VPC等。

专门为kubernetes定制的三层网络解决方案,用于解决容器的跨主机通讯。

Flannel通过ETCD维护一张节点间路由表,详细记录了各节点子网网段。

FLannel配置

1.添加flannel网络配置信息到etcd

#/opt/kubernetes/bin/etcdctl --ca-file /opt/kubernetes/ssl/ca.pem --cert-file /opt/kubernetes/ssl/flanneld.pem --key-file /opt/kubernetes/ssl/flanneld-key.pem --no-sync -C https://192.168.56.11:2379,https://192.168.56.14:2379 mk /kubernetes/network/config '{"Network": "10.3.0.0/16","Backend":{"Type": "vxlan", "VNI": 1}}'

2.安装flannel

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

tar zxf flannel-v0.10.0-linux-amd64.tar.gz

cp flanneld mk-docker-opts.sh /opt/kubernetes/bin/

3.配置flannel

cat /opt/kubernetes/cfg/flannel
FLANNEL_ETCD="-etcd-endpoints=https://192.168.56.11:2379,https://192.168.56.14:2379"
FLANNEL_ETCD_KEY="-etcd-prefix=/kubernetes/network"
FLANNEL_ETCD_CAFILE="--etcd-cafile=/opt/kubernetes/ssl/ca.pem"
FLANNEL_ETCD_CERTFILE="--etcd-certfile=/opt/kubernetes/ssl/flanneld.pem"
FLANNEL_ETCD_KEYFILE="--etcd-keyfile=/opt/kubernetes/ssl/flanneld-key.pem"

cat /usr/lib/systemd/system/flannel.service 
[Unit]
Description=Flanneld overlay address etcd agent
After=network.target
Before=docker.service

[Service]
EnvironmentFile=-/opt/kubernetes/cfg/flannel
#ExecStartPre=/opt/kubernetes/bin/remove-docker0.sh
ExecStart=/opt/kubernetes/bin/flanneld ${FLANNEL_ETCD} ${FLANNEL_ETCD_KEY} ${FLANNEL_ETCD_CAFILE} ${FLANNEL_ETCD_CERTFILE} ${FLANNEL_ETCD_KEYFILE}
ExecStartPost=/opt/kubernetes/bin/mk-docker-opts.sh -d /run/flannel/docker

Type=notify

[Install]
WantedBy=multi-user.target
RequiredBy=docker.service

4.启动

启动flannel之后,重启docker

 

上一篇:flannel+docker环境部署,无坑


下一篇:kubernetes跨网段pod网络不通问题