docker結合flannel網絡

Etcd安裝

生產環境建議使用集羣方式

wget https://github.com/etcd-io/etcd/releases/download/v3.3.15/etcd-v3.3.15-linux-amd64.tar.gz
tar -zxvf etcd-v3.3.15-linux-amd64.tar.gz && cd etcd-v3.3.15-linux-amd64
mv etcd* /usr/local/bin/
mkdir /var/lib/etcd/


cat /usr/lib/systemd/system/etcd.service 
[Unit]
Description=Etcd Server
After=netNork.target
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/local/bin/etcd \
--name=etcd \
--data-dir=/var/lib/etcd/default.etcd \
--listen-peer-urls=http://192.168.3.155:2380 \
--listen-client-urls=http://192.168.3.155:2379,http://127.0.0.1:2379 \
--advertise-client-urls=http://192.168.3.155:2379 \
--initial-advertise-peer-urls=http://192.168.3.155:2380 \
--initial-cluster=etcd=http://192.168.3.155:2380 \
--initial-cluster-token=etcd-cluster \
--initial-cluster-state=new
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target


systemctl start etcd

image.png


安裝flannel

yum -y install flannel


cat /etc/sysconfig/flanneld

FLANNEL_ETCD_ENDPOINTS="http://192.168.3.155:2379"

FLANNEL_ETCD_PREFIX="/atomic.io/network"


註冊flannel的網絡配置到etcd

3.3.15版本默認api爲V3,flannel支持V2版本

ETCDCTL_API=2 etcdctl --endpoint=http://192.168.3.155:2379 set /atomic.io/network/config '{"Network":"172.17.0.0/16", "SubnetMin": "172.17.1.0", "SubnetMax": "172.17.254.0", "Backend": {"Type": "vxlan"}}'


systemctl start flannel

Flannel啓動後,將從etcd獲取網絡配置信息

劃分子網並在etcd中註冊

將網絡配置寫入/run/flannel/subnet.env,並通過腳本生成/run/flannel/docker文件

image.png

查看etcd註冊信息

image.png


修改docker啓動參數

cat /usr/lib/systemd/system/docker.service

EnvironmentFile=/var/run/flannel/docker

ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS


systemctl daemon-reload && systemctl restart docker


查看IP

image.png


參考:

https://coreos.com/flannel/docs/latest/running.html#docker-integration

https://coreos.com/flannel/docs/latest/flannel-config.html

https://github.com/etcd-io/etcd

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章