Note:- We can run any command on only on master not on any worker node, If you run any command on any worker node it will give error.
it will good if Master is in number:- (n-1)/2 -----3,5,7
Master:-
If you want to know the master or worker token key then run below command
Key to join as worker:-
[root@ip-172-31-40-90 ~]# docker swarm join-token worker
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-4z0bipbsxzoy2ccn5m22eiems1w0a5du8rlyt6nbvdq3pfegm8-1z76g4wwivmk1s0cp8dethxav 172.31.40.90:2377
Key to join as master:-
[root@ip-172-31-40-90 ~]# docker swarm join-token manager
To add a manager to this swarm, run the following command:
docker swarm join --token SWMTKN-1-4z0bipbsxzoy2ccn5m22eiems1w0a5du8rlyt6nbvdq3pfegm8-5go59kirhawvq08kdot5umv0m 172.31.40.90:2377
[root@ip-172-31-40-90 ~]#
[root@ip-172-31-40-90 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
q0yqpe0fsihtmoaj1834s1tnf ip-172-31-35-189 Ready Active 18.06.1-ce
rby7qdb8hc3ebuuy78vpl0i4v * ip-172-31-40-90 Ready Active Leader 18.06.1-ce
pzcz2fs38ks9vrwecn30txuv9 ip-172-31-43-91 Ready Active 18.06.1-ce
[root@ip-172-31-40-90 ~]#
After Worker02 left
[root@ip-172-31-40-90 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
q0yqpe0fsihtmoaj1834s1tnf ip-172-31-35-189 Ready Active 18.06.1-ce
rby7qdb8hc3ebuuy78vpl0i4v * ip-172-31-40-90 Ready Active Leader 18.06.1-ce
pzcz2fs38ks9vrwecn30txuv9 ip-172-31-43-91 Down Active 18.06.1-ce
[root@ip-172-31-40-90 ~]#
To remove the Down node(Worker02)
[root@ip-172-31-40-90 ~]# docker node rm pzcz2fs38ks9vrwecn30txuv9
pzcz2fs38ks9vrwecn30txuv9
[root@ip-172-31-40-90 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
q0yqpe0fsihtmoaj1834s1tnf ip-172-31-35-189 Ready Active 18.06.1-ce
rby7qdb8hc3ebuuy78vpl0i4v * ip-172-31-40-90 Ready Active Leader 18.06.1-ce
[root@ip-172-31-40-90 ~]#
Worker01:-
After removing forcefully also by master here it will show active ,So to make it inactive run the below command
[root@ip-172-31-35-189 ~]# docker swarm leave
Node left the swarm.
[root@ip-172-31-35-189 ~]#
[root@ip-172-31-35-189 ~]# docker swarm join --token SWMTKN-1-4z0bipbsxzoy2ccn5m22eiems1w0a5du8rlyt6nbvdq3pfegm8-1z76g4wwivmk1s0cp8dethxav 172.31.40.90:2377
This node joined a swarm as a worker.
[root@ip-172-31-35-189 ~]#
Worker02:-
To leave the cluster
[root@ip-172-31-43-91 ~]# docker swarm leave
Node left the swarm.
[root@ip-172-31-43-91 ~]# docker info
it will good if Master is in number:- (n-1)/2 -----3,5,7
Master:-
If you want to know the master or worker token key then run below command
Key to join as worker:-
[root@ip-172-31-40-90 ~]# docker swarm join-token worker
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-4z0bipbsxzoy2ccn5m22eiems1w0a5du8rlyt6nbvdq3pfegm8-1z76g4wwivmk1s0cp8dethxav 172.31.40.90:2377
Key to join as master:-
[root@ip-172-31-40-90 ~]# docker swarm join-token manager
To add a manager to this swarm, run the following command:
docker swarm join --token SWMTKN-1-4z0bipbsxzoy2ccn5m22eiems1w0a5du8rlyt6nbvdq3pfegm8-5go59kirhawvq08kdot5umv0m 172.31.40.90:2377
[root@ip-172-31-40-90 ~]#
[root@ip-172-31-40-90 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
q0yqpe0fsihtmoaj1834s1tnf ip-172-31-35-189 Ready Active 18.06.1-ce
rby7qdb8hc3ebuuy78vpl0i4v * ip-172-31-40-90 Ready Active Leader 18.06.1-ce
pzcz2fs38ks9vrwecn30txuv9 ip-172-31-43-91 Ready Active 18.06.1-ce
[root@ip-172-31-40-90 ~]#
[root@ip-172-31-40-90 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
q0yqpe0fsihtmoaj1834s1tnf ip-172-31-35-189 Ready Active 18.06.1-ce
rby7qdb8hc3ebuuy78vpl0i4v * ip-172-31-40-90 Ready Active Leader 18.06.1-ce
pzcz2fs38ks9vrwecn30txuv9 ip-172-31-43-91 Down Active 18.06.1-ce
[root@ip-172-31-40-90 ~]#
To remove the Down node(Worker02)
[root@ip-172-31-40-90 ~]# docker node rm pzcz2fs38ks9vrwecn30txuv9
pzcz2fs38ks9vrwecn30txuv9
[root@ip-172-31-40-90 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
q0yqpe0fsihtmoaj1834s1tnf ip-172-31-35-189 Ready Active 18.06.1-ce
rby7qdb8hc3ebuuy78vpl0i4v * ip-172-31-40-90 Ready Active Leader 18.06.1-ce
[root@ip-172-31-40-90 ~]#
Now to remove active node
[root@ip-172-31-40-90 ~]# docker node rm -f q0yqpe0fsihtmoaj1834s1tnf
q0yqpe0fsihtmoaj1834s1tnf
[root@ip-172-31-40-90 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
rby7qdb8hc3ebuuy78vpl0i4v * ip-172-31-40-90 Ready Active Leader 18.06.1-ce
[root@ip-172-31-40-90 ~]#
Now again to add both worker node run the below command in both worker machine
docker swarm join --token SWMTKN-1-4z0bipbsxzoy2ccn5m22eiems1w0a5du8rlyt6nbvdq3pfegm8-1z76g4wwivmk1s0cp8dethxav 172.31.40.90:2377
After running the above line in both the worker
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
af3y6rhgp328s777kw26g7co2 ip-172-31-35-189 Ready Active 18.06.1-ce
rby7qdb8hc3ebuuy78vpl0i4v * ip-172-31-40-90 Ready Active Leader 18.06.1-ce
u9sg7rw8yvb75o5ybrnppeglo ip-172-31-43-91 Ready Active 18.06.1-ce
[root@ip-172-31-40-90 ~]#
again both worker added to cluster
Worker01:-
After removing forcefully also by master here it will show active ,So to make it inactive run the below command
[root@ip-172-31-35-189 ~]# docker swarm leave
Node left the swarm.
[root@ip-172-31-35-189 ~]#
[root@ip-172-31-35-189 ~]# docker swarm join --token SWMTKN-1-4z0bipbsxzoy2ccn5m22eiems1w0a5du8rlyt6nbvdq3pfegm8-1z76g4wwivmk1s0cp8dethxav 172.31.40.90:2377
This node joined a swarm as a worker.
[root@ip-172-31-35-189 ~]#
Worker02:-
To leave the cluster
[root@ip-172-31-43-91 ~]# docker swarm leave
Node left the swarm.
[root@ip-172-31-43-91 ~]# docker info
Swarm: inactive
[root@ip-172-31-43-91 ~]# docker swarm join --token SWMTKN-1-4z0bipbsxzoy2ccn5m22eiems1w0a5du8rlyt6nbvdq3pfegm8-1z76g4wwivmk1s0cp8dethxav 172.31.40.90:2377
This node joined a swarm as a worker.
[root@ip-172-31-43-91 ~]#
No comments:
Post a Comment