Thank you for reading this post, don't forget to subscribe!
Имеется несколько хостов:
192.168.1.180 swarm_master1_180
192.168.1.181 swarm_master2_181
192.168.1.182 swarm_master3_182
192.168.1.183 swarm_node1_183
192.168.1.184 swarm_node2_184
192.168.1.185 swarm_node3_185
инициируем кластер:
[root@swarm_master1_180~]# docker swarm init
Для добавления второй управляющей ноды, выполним команду на действующей управляющей ноде
1 2 3 |
<span style="font-family: georgia, palatino, serif;">[root@swarm_master1_180~]# <strong>docker swarm join-token manager</strong></span> <span style="font-family: georgia, palatino, serif;">To add a manager to this swarm, run the following command:</span> <span style="font-family: georgia, palatino, serif;">docker swarm join --token SWMTKN-1-3ce1cv9a3lh4eulgw93epia3ksv4jds8bx6sx5y4ifeooaxvid-8v82bfxc20bu4telzgo9p2rq7 192.168.1.180:2377</span> |
[root@swarm_master2_181~]# docker swarm join --token SWMTKN-1-3ce1cv9a3lh4eulgw93epia3ksv4jds8bx6sx5y4ifeooaxvid-8v82bfxc20bu4telzgo9p2rq7 192.168.1.180:2377
This node joined a swarm as a manager.
[root@swarm_master3_182~]# docker swarm join --token SWMTKN-1-3ce1cv9a3lh4eulgw93epia3ksv4jds8bx6sx5y4ifeooaxvid-8v82bfxc20bu4telzgo9p2rq7 192.168.1.180:2377
This node joined a swarm as a manager.
теперь добавляем воркеры:
на мастере выполняем команду:
[root@swarm_master1_180~]# docker swarm join-token worker
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-3ce1cv9a3lh4eulgw93epia3ksv4jds8bx6sx5y4ifeooaxvid-b4hyll4eh37i9vd15zzwft0tn 192.168.1.180:2377
[root@swarm_node1_183 ~]# docker swarm join --token SWMTKN-1-3ce1cv9a3lh4eulgw93epia3ksv4jds8bx6sx5y4ifeooaxvid-b4hyll4eh37i9vd15zzwft0tn 192.168.1.180:2377
This node joined a swarm as a worker.
[root@swarm_node2_184 ~]# docker swarm join --token SWMTKN-1-3ce1cv9a3lh4eulgw93epia3ksv4jds8bx6sx5y4ifeooaxvid-b4hyll4eh37i9vd15zzwft0tn 192.168.1.180:2377
This node joined a swarm as a worker.
[root@swarm_node3_185 ~]# docker swarm join --token SWMTKN-1-3ce1cv9a3lh4eulgw93epia3ksv4jds8bx6sx5y4ifeooaxvid-b4hyll4eh37i9vd15zzwft0tn 192.168.1.180:2377
This node joined a swarm as a worker.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
проверяем: [root@swarm_master1_180 ~]# <strong>docker node ls</strong> ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION 0ihuax8tievdrp3m8xjz5v1ys * swarm_master1_180 Ready Active Leader 19.03.1 wmsi0eehhm0j8pfm39mbeifni swarm_master2_181 Ready Active Reachable 19.03.1 trcwny82y87kf60ts1h6rogpa swarm_master3_182 Ready Active Reachable 19.03.1 z9jxfogx18aadldbotsbqhofa swarm_node1_183 Ready Active 19.03.1 y13tvpnm3oi520ab4tc891y7q swarm_node2_184 Ready Active 19.03.1 2u47nhxy05amaut0ljehr5hwe swarm_node3_185 Ready Active 19.03.1 готово кластер установлен. ==================================================== чтобы вывести ноды из кластера, например мастера, для начала понижаем его роль: |
[root@swarm_master1_180 ~]# docker node demote 0ihuax8tievdrp3m8xjz5v1ys
Manager 0ihuax8tievdrp3m8xjz5v1ys demoted in the swarm.
после покидаем сам кластер:
[root@swarm_master1_180 ~]# docker swarm leave
Node left the swarm.
далее можем удалять ноды:
[root@swarm_master3_182 ~]# docker node rm 2u47nhxy05amaut0ljehr5hwe
2u47nhxy05amaut0ljehr5hwe
[root@swarm_master3_182 ~]# docker node rm y13tvpnm3oi520ab4tc891y7q
y13tvpnm3oi520ab4tc891y7q
[root@swarm_master3_182 ~]# docker node rm z9jxfogx18aadldbotsbqhofa
z9jxfogx18aadldbotsbqhofa