Learning Academy

The Cure of Ignorance is to Question. MUHAMMAD (PBUH)

LinuxRocky

Deploying Docker Swarm on Rocky Linux

Welcome to an exciting and practical journey into container orchestration!
In this guide, you will deploy a highly available Docker Swarm cluster across three Rocky Linux servers. Through a series of carefully structured steps, you will gain hands-on experience installing, configuring, and managing containerized services on Rocky Linux, sharpening your skills in modern IT infrastructure and cloud-native technologies. By the end of this exercise, you will be better equipped to manage and scale containerized applications confidently and efficiently.


Testbed Configuration

HostIP Address
SwarmManager192.168.10.131
RNode1192.168.10.135
RNode2192.168.10.136

Step 1: Initial Configuration of SwarmManager Node

Begin by preparing the Swarm Manager node:

# Add Docker repository

1
sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

# Verify repository list

1
sudo dnf repo list

# Update the system

1
sudo dnf update -y

# Install Docker Engine and related components

1
sudo dnf install docker-ce docker-ce-cli containerd.io -y

# Enable and start the Docker service

1
sudo systemctl enable docker

1
sudo systemctl start docker

# Add user to Docker group for non-root access

1
sudo usermod -aG docker <user>

# Configure Firewall for Swarm Communication

1
sudo firewall-cmd --add-port=2377/tcp --permanent 

1
sudo firewall-cmd --add-port=7946/tcp --permanent 

1
sudo firewall-cmd --add-port=7946/udp --permanent

1
sudo firewall-cmd --add-port=4789/udp --permanent 

1
sudo firewall-cmd --add-port=8000/tcp

1
sudo firewall-cmd --reload

# Initialize Docker Swarm

1
docker swarm init --advertise-addr 192.168.10.131 --default-addr-pool 10.10.0.0/16

Step 2: Adding Worker Nodes to the Swarm

Now, configure each worker node to join the cluster.

RNode1 Setup:

# Update and prepare the system

1
sudo dnf update -y

1
sudo dnf install -y dnf-utils

# Add Docker repository

1
sudo dnf config-manager --add-repo=https://download.docker.com/linux/rhel/docker-ce.repo

# Install Docker Engine and related components

1
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Enable and start Docker

1
sudo systemctl --now enable docker

# Add user to Docker group

1
sudo usermod -aG docker <user>

# Allow necessary firewall ports

1
sudo firewall-cmd --add-port=8000/tcp

1
sudo firewall-cmd --reload

# Join the Swarm cluster

1
docker swarm join --token <your-token> 192.168.10.131:2377

Note: Replace <your-token> with the actual token generated during the Swarm initialization.

RNode2 Setup:

# Update and prepare the system

1
sudo dnf update -y

1
sudo dnf install -y dnf-utils

# Add Docker repository

1
sudo dnf config-manager --add-repo=https://download.docker.com/linux/rhel/docker-ce.repo

# Install Docker Engine and related components

1
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Enable and start Docker

1
sudo systemctl --now enable docker

# Add user to Docker group

1
sudo usermod -aG docker &lt;user>

# Allow necessary firewall ports

1
sudo firewall-cmd --add-port=8000/tcp

1
sudo firewall-cmd --reload

# Join the Swarm cluster

1
docker swarm join --token &lt;your-token> 192.168.10.131:2377


Step 3: Verifying Swarm Node Status

Confirm that all nodes have successfully joined the cluster:

# List all nodes in the Swarm

1
docker node ls

# Detailed Swarm information

1
docker info

You should observe three nodes: one Manager and two Workers.


Step 4: Creating and Managing Services on Docker Swarm

Launch your first containerized service on the Swarm:

# Deploy a simple HTTP service

1
docker service create --replicas 1 --name test-httpd -p 8000:80 httpd:alpine

# Verify the service

1
docker service ls

1
docker service inspect test-httpd

1
docker service inspect --pretty test-httpd

1
docker service ps test-httpd

# Test service availability

1
curl 192.168.10.131:8000


Step 5: Scaling Services Dynamically

Experience the power of scaling services with a single command:

# Scale the service to 3 replicas

1
docker service scale test-httpd=3

# Verify replica distribution

1
docker service ps test-httpd


Step 6: Testing Service Across Nodes

Validate service accessibility across different nodes:

# List running containers

1
docker ps

# Test service on each node

1
curl http://192.168.10.135:8000

1
curl http://192.168.10.136:8000

You should receive consistent responses, demonstrating load distribution and service availability across your Swarm cluster!


Conclusion

Congratulations! By completing this guide, you have successfully deployed and managed a multi-node Docker Swarm cluster on Rocky Linux. You now possess fundamental expertise in container orchestration, service scaling, and distributed system management, critical skills that are in high demand across the IT industry. Keep experimenting, keep building, and let this accomplishment fuel your journey into the vast world of cloud-native technologies!

Muhammad Shaukat

Content Developer at LearnAcad.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest