In this lesson, you’ll learn how to:Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
- Promote and demote Swarm nodes
- Drain nodes for maintenance
- Remove nodes from your cluster
Promote and Demote Nodes
Only Swarm manager nodes can orchestrate the cluster. You can elevate a worker node to manager or revert a manager back to a worker. Run these commands on any current manager.Promote a Worker to Manager
Promoting a node requires you to be connected to an active manager. Check your current context with
docker info.| ID | HOSTNAME | STATUS | AVAILABILITY | MANAGER STATUS | ENGINE VERSION |
|---|---|---|---|---|---|
| 91uxgq6… | manager1 | Ready | Active | Leader | 19.03.8 |
| 2lux7z6… | worker1 | Ready | Active | Reachable | 19.03.8 |
| w0qr6k2… | worker2 | Ready | Active | 19.03.8 |
Demote a Manager to Worker
| ID | HOSTNAME | STATUS | AVAILABILITY | MANAGER STATUS | ENGINE VERSION |
|---|---|---|---|---|---|
| 91uxgq6… | manager1 | Ready | Active | Leader | 19.03.8 |
| 2lux7z6… | worker1 | Ready | Active | 19.03.8 | |
| w0qr6k2… | worker2 | Ready | Active | 19.03.8 |
Drain a Node for Maintenance
Before patching or upgrading, remove workloads from a node to avoid downtime. The following diagram shows a Swarm cluster with one manager and two workers running a “Web” service.
worker1 to migrate its tasks:
Draining a node stops new tasks from being scheduled and reschedules existing ones on other workers. Ensure your cluster has enough capacity before draining.
| ID | HOSTNAME | STATUS | AVAILABILITY | MANAGER STATUS | ENGINE VERSION |
|---|---|---|---|---|---|
| 91uxgq6… | manager1 | Ready | Active | Leader | 19.03.8 |
| 2lux7z6… | worker1 | Ready | Drain | 19.03.8 | |
| w0qr6k2… | worker2 | Ready | Active | 19.03.8 |
worker1 will accept new tasks:
| ID | HOSTNAME | STATUS | AVAILABILITY | MANAGER STATUS | ENGINE VERSION |
|---|---|---|---|---|---|
| 91uxgq6… | manager1 | Ready | Active | Leader | 19.03.8 |
| 2lux7z6… | worker1 | Ready | Active | 19.03.8 | |
| w0qr6k2… | worker2 | Ready | Active | 19.03.8 |
Remove a Node from the Swarm
To permanently remove a worker node:-
Drain the node:
-
Log in to
worker2and leave the swarm:
worker2 is safely removed, and your cluster continues with the remaining nodes.