1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| # etcd里面存储一个子网信息 $ etcdctl --endpoints="http://172.16.100.92:2379" put /coreos.com/network/config '{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}' # 查看 $ etcdctl --endpoints="http://172.16.100.92:2379" get /coreos.com/network/config
# 二进制包上传上服务器 $ tar zxvf flannel-v0.11.0-linux-amd64.tar.gz $ mv flanneld mk-docker-opts.sh /usr/local/bin
# 新建启动环境变量 $ cat /soyuan/k8s/cfg/flanneld FLANNEL_OPTIONS="--etcd-endpoints=http://172.16.100.92:2379"
# 新建系统服务文件 $ cat /usr/lib/systemd/system/flanneld.service
[Unit] Description=Flanneld overlay address etcd agent After=network-online.target network.target Before=docker.service [Service] Type=notify EnvironmentFile=/soyuan/k8s/cfg/flanneld ExecStart=/usr/local/bin/flanneld --ip-masq $FLANNEL_OPTIONS ExecStartPost=/usr/local/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/subnet.env # 生成docker的网段参数 Restart=on-failure
[Install] WantedBy=multi-user.target
# 启动服务 $ systemctl daemon-reload $ systemctl start flanneld $ systemctl enable flanneld
# 配置Docker启动指定子网段 $ cat /usr/lib/systemd/system/docker.service
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target
[Service] Type=notify EnvironmentFile=/run/flannel/subnet.env ExecStart=/usr/local/bin/dockerd $DOCKER_NETWORK_OPTIONS -H tcp://0.0.0.0:2371 -H unix:///var/run/docker.sock ExecReload=/bin/kill -s HUP $MAINPID LimitNOFILE=infinity LimitNPROC=infinity TimeoutStartSec=0 Delegate=yes KillMode=process Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s
[Install] WantedBy=multi-user.target
# 重启docker $ systemctl daemon-reload $ systemctl restart docker
# /etc/docker/daemon.json 不要重复配置bip
|
flanneld 不能和etcd v3通信问题
Couldn't fetch network config: client: response is invalid json. The endpoint is probably not valid etcd cluster endpoint
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| # 删除刚才创建的key $ etcdctl get --prefix /coreos.com $ etcdctl del /coreos.com/network/config
# 在etcd启动参数里面加入 --enable-v2 参数 [Unit] Description=Etcd service After=network.target
[Service] Type=simple WorkingDirectory=/soyuan/k8s/etcd EnvironmentFile=-/soyuan/k8s/etcd/etcd.conf ExecStart=/usr/local/bin/etcd --enable-v2
[Install] WantedBy=multi-user.target
# 重启etcd $ systemctl daemon-reload $ systemctl restart etcd
# 重新导入参数 $ ETCDCTL_API=2 etcdctl --endpoints="http://172.16.100.92:2379" set /coreos.com/network/config '{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}'
# 参看配置 $ ETCDCTL_API=2 etcdctl get /coreos.com/network/config
|