- Initialize the swarm
- Join worker nodes
- Promote and demote managers
- Drain and reactivate nodes
- Remove nodes from the cluster
- Three CentOS 7.6 servers (
managerone,workerone,workertwo) - 2 CPU cores and 4 GB RAM each
- Hostname resolution (e.g., via
/etc/hostsor DNS) - Open ports:
- TCP 2377 for cluster management
- TCP/UDP 7946 for node discovery
- UDP 4789 for overlay networking
- Docker Engine installed and running
System Overview
| Node | OS Release | CPUs | Memory (MiB) | Docker Version |
|---|---|---|---|---|
| managerone | CentOS Linux release 7.6.1810 (Core) | 2 | 3787 | 19.03.8 |
| workerone | CentOS Linux release 7.6.1810 (Core) | 2 | 3787 | 19.03.8 |
| workertwo | CentOS Linux release 7.6.1810 (Core) | 2 | 3787 | 19.03.8 |
1. Initialize the Swarm on managerone
-
Confirm Swarm is inactive:
-
Initialize with the manager’s advertise address:
After initialization, note the worker join command output:
2. Add the First Worker (workerone)
On workerone, run the join command displayed by the manager:
3. Add the Second Worker (workertwo)
3.1. Prepare workertwo
Ensure OS, CPU, memory, Docker version, and connectivity:
3.2. Retrieve and Run the Join Token
On managerone, print the worker join command:docker swarm join --token … line and execute it on workertwo. Then confirm on managerone:
4. Promote a Worker to Manager
-
List current nodes:
-
Promote workerone:
-
Verify the new manager status:
-
(Optional) Inspect workerone in detail:
5. Demote a Manager back to Worker
If you need to revert workerone to a purely worker role:6. Drain and Reactivate a Node
To prevent new tasks from scheduling on workerone:7. Remove a Node from the Swarm
-
Drain workerone:
-
Attempt removal (will fail if the node is still up):
-
On workerone, leave the swarm:
-
Back on managerone, remove the node: