在首次启动flannel服务的时候可以手动指定subnet.env文件,配置所在节点的flannel子网网段,如果不指定配置文件,flannel将自动分配一个子网网段并生成配置文件 /var/run/flannel/subnet.env,配置信息写入etcd集群。
如果节点失效超时,etcd将清除该节点的子网信息。在不移除节点的情况下,修改配置文件并重启flannel服务,flannel会将etcd中的信息写回subnet.env,即subnet.env文件会被重置。因此必须通过修改etcd来修改节点flannel子网信息。
[root@master1 ~]# etcdctl ls /coreos.com/network/subnets/ /coreos.com/network/subnets/172.7.16.0-24 /coreos.com/network/subnets/172.7.17.0-24 /coreos.com/network/subnets/172.7.28.0-24 [root@master1 ~]# etcdctl set /coreos.com/network/subnets/172.7.18.0-24 '{"PublicIP":"172.25.25.18","BackendType":"host-gw"}' {"PublicIP":"172.25.25.18","BackendType":"host-gw"} [root@master1 ~]# etcdctl ls /coreos.com/network/subnets/ /coreos.com/network/subnets/172.7.16.0-24 /coreos.com/network/subnets/172.7.17.0-24 /coreos.com/network/subnets/172.7.28.0-24 /coreos.com/network/subnets/172.7.18.0-24 [root@master1 ~]# etcdctl get /coreos.com/network/subnets/172.7.28.0-24 {"PublicIP":"172.25.25.18","BackendType":"host-gw"} [root@master1 ~]# etcdctl get /coreos.com/network/subnets/172.7.18.0-24 {"PublicIP":"172.25.25.18","BackendType":"host-gw"} [root@master1 ~]# etcdctl rm /coreos.com/network/subnets/172.7.28.0-24 PrevNode.Value: {"PublicIP":"172.25.25.18","BackendType":"host-gw"} [root@master1 ~]# etcdctl ls /coreos.com/network/subnets/ /coreos.com/network/subnets/172.7.16.0-24 /coreos.com/network/subnets/172.7.17.0-24 /coreos.com/network/subnets/172.7.18.0-24 [root@master1 ~]# etcdctl get /coreos.com/network/subnets/172.7.18.0-24 {"PublicIP":"172.25.25.18","BackendType":"host-gw"} [root@master1 ~]# etcdctl get /coreos.com/network/subnets/172.7.17.0-24 {"PublicIP":"172.25.25.17","BackendType":"host-gw"} [root@master1 ~]# etcdctl get /coreos.com/network/subnets/172.7.16.0-24 {"PublicIP":"172.25.25.16","BackendType":"host-gw"}