运维之我的docker-swarm集群中删除节点和服务
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了运维之我的docker-swarm集群中删除节点和服务相关的知识,希望对你有一定的参考价值。
删除swam节点
如果有的确实想要从swarm集群中删除,你应该先把这个节点容器排空,然后再把节点从集群中去掉。
排空节点(其实就是把这个节点上的容器先从其它节点启动,再停掉排空节点上的容器,保证你定义服务的预先状态不受影响)
docker node update --availability drain g36lvv23ypjd8v7ovlst2n3yt
删除指定节点
docker node rm node9
docker node rm --force node9
删除服务
删除服务以后容器也会删除,注意:容器删除会延迟一定时间。
[[email protected] salt]# docker service rm cache_cluster2
cache_cluster2
下面操作强烈不建议随意操作
离开swarm集群(离开后发现在manager里面这个节点是down的状态,当然这状态变化是有延时的,因为需要迁移容器)
[[email protected] ~]# docker swarm leave Node left the swarm. [[email protected] 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
删除服务
删除服务以后容器也会删除,注意:容器删除会延迟一定时间。
[[email protected] salt]# docker service rm cache_cluster2
cache_cluster2
下面做了一个实验,清空一个节点后你会看到这个节点似的状态变为Drain ,容器变为shutdown
查看集群内的容器状态
[[email protected] 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
排空一个节点
[[email protected] salt]# docker node update --availability drain g36lvv23ypjd8v7ovlst2n3yt g36lvv23ypjd8v7ovlst2n3yt [[email protected] 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 [[email protected] 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一个节点
[[email protected] salt]# docker node update --availability Active g36lvv23ypjd8v7ovlst2n3yt g36lvv23ypjd8v7ovlst2n3yt
本文出自 “运维之我的历程” 博客,转载请与作者联系!
以上是关于运维之我的docker-swarm集群中删除节点和服务的主要内容,如果未能解决你的问题,请参考以下文章