In Docker Swarm, you can promote a worker node to a manager or demote a manager to a worker using the docker node promote and docker node demote commands, respectively. These commands help in managing the roles of nodes within the Swarm.
Promote a Worker Node to a Manager:
Current Status :
[root@siddhesh ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
ieh09e2qqupx90mhmr1k08hm3 * siddhesh Ready Active Leader
xjrwvile6z8jmj762e2svidas slave.builddevops.com Ready Active
[root@siddhesh ~]#
Where,
The node with ID 'ieh09e2qqupx90mhmr1k08hm3' is currently acting as a manager, while the node with ID 'xjrwvile6z8jmj762e2svidas' is acting as a worker. Let's now try to promote the worker node to a manager.
[root@siddhesh ~]# docker node promote xjrwvile6z8jmj762e2svidas
Node xjrwvile6z8jmj762e2svidas promoted to a manager in the swarm.
[root@siddhesh ~]#
In the above output, xjrwvile6z8jmj762e2svidas: This is the ID or hostname of the node that you want to promote to a manager.
promoted to a manager in the swarm: This message indicates that the specified node (xjrwvile6z8jmj762e2svidas) has been successfully promoted to the role of a manager in the Docker Swarm.
Demote a Manager Node to Worker:
[root@siddhesh ~]# docker node demote ieh09e2qqupx90mhmr1k08hm3
Manager ieh09e2qqupx90mhmr1k08hm3 demoted in the swarm.
[root@siddhesh ~]#
ieh09e2qqupx90mhmr1k08hm3: This is the ID or hostname of the node that you want to demote from the role of a manager to a worker.
demoted in the swarm: This message indicates that the specified node (ieh09e2qqupx90mhmr1k08hm3) has been successfully demoted from the role of a manager to that of a worker in the Docker Swarm.
Check Final Status:
To verify the final status, we need to log in to the host that was previously acting as a worker, as we have now shifted the manager role to this host.
[root@slave ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
ieh09e2qqupx90mhmr1k08hm3 siddhesh Ready Active
xjrwvile6z8jmj762e2svidas * slave.builddevops.com Ready Active Leader
[root@slave ~]#
In the given output you can now see that node xjrwvile6z8jmj762e2svidas is acting as a manager. Additionally, ensure that your Swarm configuration has enough managers to maintain quorum for high availability.
Very Informative