获取node信息
docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
j52o5frhmphiksqz0xq1mkbbh * node1 Ready Active Leader 18.09.7
nq6v8dog0xzgpzx51x7bv59bp node2 Ready Active 18.09.7
6whtoqrhkzv3ax4xy9ab20gmy node3 Ready Active 18.09.7
让 node3 离开,排空 node3 的容器(在 master 上操作)
docker node update --availability drain 6whtoqrhkzv3ax4xy9ab20gmy
让 node3 主动离开集群,让节点处于down状态 (在 node3 上操作)
docker swarm leave
删除 node节点(在 master 上操作)
docker node rm 6whtoqrhkzv3ax4xy9ab20gmy
添加删除节点
[root@k8s-node1 ~]# docker swarm join --token SWMTKN-1-1f349i4b2etn0ods4l2q03dcr2l25qdmb5u9472uv2s015i9pr-1mum48hmekeqgbs55lbh536ql 10.0.23.156:2377
Error response from daemon: This node is already part of a swarm. Use "docker swarm leave" to leave this swarm and join another one.
报错是之前删除node是直接rm没有 执行排空、制动离开
解决办法:
要加入的node上执行
[root@k8s-node1 ~]# docker swarm leave
Node left the swarm.
在执行加入集群
[root@k8s-node1 ~]# docker swarm join --token SWMTKN-1-1f349i4b2etn0ods4l2q03dcr2l25qdmb5u9472uv2s015i9pr-1mum48hmekeqgbs55lbh536ql 10.0.23.156:2377
This node joined a swarm as a manager.
master上执行就可以看到了
如token忘了可以执行获取token(master上操作)
[root@k8s-master1 ]# docker swarm join-token manager
To add a manager to this swarm, run the following command:
docker swarm join
--token SWMTKN-1-1f349i4b2etn0ods4l2q03dcr2l25qdmb5u9472uv2s015i9pr-1mum48hmekeqgbs55lbh536ql
10.0.23.156:2377