千家信息网

docker结合flannel网络

发表于:2024-11-17 作者:千家信息网编辑
千家信息网最后更新 2024年11月17日,Etcd安装生产环境建议使用集群方式wget https://github.com/etcd-io/etcd/releases/download/v3.3.15/etcd-v3.3.15-linux-
千家信息网最后更新 2024年11月17日docker结合flannel网络

Etcd安装

生产环境建议使用集群方式

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


cat /usr/lib/systemd/system/etcd.service [Unit]Description=Etcd ServerAfter=netNork.targetAfter=network-online.targetWants=network-online.target[Service]Type=notifyExecStart=/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=newRestart=on-failureLimitNOFILE=65536[Install]WantedBy=multi-user.target


systemctl start etcd


安装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文件

查看etcd注册信息


修改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


参考:

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

0