运维之我的docker-swarm集群中删除节点和服务
删除swam节点如果有的确实想要从swarm集群中删除,你应该先把这个节点容器排空,然后再把节点从集群中去掉。排空节点(其实就是把这个节点上的容器先从其它节点启动,再停掉排空节点上的容器,保证你定义服务的预先状态不受影响)docker node update --availability drain g36lvv23ypjd8v7ovlst2n3yt删除指...
删除swam节点
如果有的确实想要从swarm集群中删除,你应该先把这个节点容器排空,然后再把节点从集群中去掉。
排空节点(其实就是把这个节点上的容器先从其它节点启动,再停掉排空节点上的容器,保证你定义服务的预先状态不受影响)
docker node update --availability drain g36lvv23ypjd8v7ovlst2n3yt
删除指定节点
docker node rm node9
docker node rm --force node9
删除服务
删除服务以后容器也会删除,注意:容器删除会延迟一定时间。
[root@salt-node1 salt]# docker service rm cache_cluster2
cache_cluster2
下面操作强烈不建议随意操作
离开swarm集群(离开后发现在manager里面这个节点是down的状态,当然这状态变化是有延时的,因为需要迁移容器)
[root@data-node2 ~]# docker swarm leave Node left the swarm. [root@salt-node1 pkg]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS 0jz3o2avbbugyoejzs1ed3djz data-node3 Ready Active 2pzv4kzc2p8f7c4wqlfupp9h9 * salt-node1 Ready Active Leader 37lpbieigtc2cz6njwqfe0c4b compute1 Ready Active g36lvv23ypjd8v7ovlst2n3yt salt-node3 Ready Active Reachable h14re9viizbs5yj3zunuo9zo8 salt-node2 Ready Active Reachable nuf5y9ecpeupw2eb0u9z1gt3q data-node2 Down Active
强制离开swarm集群
docker swarm leave --force
删除服务
删除服务以后容器也会删除,注意:容器删除会延迟一定时间。
[root@salt-node1 salt]# docker service rm cache_cluster2
cache_cluster2
下面做了一个实验,清空一个节点后你会看到这个节点似的状态变为Drain ,容器变为shutdown
查看集群内的容器状态
[root@salt-node1 salt]# docker service ps redis3
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
ub6zvbeayv1e redis3.1 registry.cn-hangzhou.aliyuncs.com/forker/redis:latest salt-node3 Running Running 34 minutes ago
pcgn683xixqn \_ redis3.1 redis:3.0.6 salt-node3 Shutdown Shutdown 34 minutes ago
y2tpi5kpfz0v redis3.2 registry.cn-hangzhou.aliyuncs.com/forker/redis:latest salt-node1 Running Running 33 minutes ago
pmsrkkpsjihp \_ redis3.2 redis:3.0.6 salt-node1 Shutdown Shutdown 33 minutes ago
w75q4im55w0l redis3.3 registry.cn-hangzhou.aliyuncs.com/forker/redis:latest salt-node2 Running Running 34 minutes ago
mc0badk4bk4h \_ redis3.3 redis:3.0.6 salt-node2 Shutdown Shutdown 34 minutes ago
排空一个节点
[root@salt-node1 salt]# docker node update --availability drain g36lvv23ypjd8v7ovlst2n3yt g36lvv23ypjd8v7ovlst2n3yt [root@salt-node1 salt]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS 2pzv4kzc2p8f7c4wqlfupp9h9 * salt-node1 Ready Active Leader g36lvv23ypjd8v7ovlst2n3yt salt-node3 Ready Drain h14re9viizbs5yj3zunuo9zo8 salt-node2 Ready Active [root@salt-node1 salt]# docker service ps redis3 ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS w0jjjrdr25eh redis3.1 registry.cn-hangzhou.aliyuncs.com/forker/redis:latest salt-node1 Running Running 30 seconds ago ub6zvbeayv1e \_ redis3.1 registry.cn-hangzhou.aliyuncs.com/forker/redis:latest salt-node3 Shutdown Shutdown 34 seconds ago pcgn683xixqn \_ redis3.1 redis:3.0.6 salt-node3 Shutdown Shutdown 11 hours ago y2tpi5kpfz0v redis3.2 registry.cn-hangzhou.aliyuncs.com/forker/redis:latest salt-node1 Running Running 11 hours ago pmsrkkpsjihp \_ redis3.2 redis:3.0.6 salt-node1 Shutdown Shutdown 11 hours ago w75q4im55w0l redis3.3 registry.cn-hangzhou.aliyuncs.com/forker/redis:latest salt-node2 Running Running 11 hours ago mc0badk4bk4h \_ redis3.3 redis:3.0.6 salt-node2 Shutdown Shutdown 11 hours ago
#恢复active一个节点
[root@salt-node1 salt]# docker node update --availability Active g36lvv23ypjd8v7ovlst2n3yt g36lvv23ypjd8v7ovlst2n3yt
转载于:https://blog.51cto.com/nginxs/1903228
更多推荐
所有评论(0)