DevOps Project-4

DevOps Project-4

·

3 min read

Project Description

The project aims to deploy a web application using Docker Swarm, a container orchestration tool that allows for easy management and scaling of containerized applications. The project will utilize Docker Swarm's production-ready features such as load balancing, rolling updates, and service discovery to ensure high availability and reliability of the web application. The project will involve creating a Dockerfile to package the application into a container and then deploying it onto a Swarm cluster. The Swarm cluster will be configured to provide automated failover, load balancing, and horizontal scaling to the application. The goal of the project is to demonstrate the benefits of Docker Swarm for deploying and managing containerized applications in production environments.

To begin, access the AWS portal and set up three new instances with Docker pre-installed. Utilize the provided shell script in the EC2 User Data field:

#!/bin/bash
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker ubuntu
sudo reboot

🔶 Establishing a Docker Swarm Cluster: Create a Docker Swarm cluster with multiple nodes for managing deployed containers:

docker swarm init

A Docker Swarm cluster can be set up on a single machine for testing or multiple machines for a production-ready setup. Docker Swarm uses port 2377, so open this port in the Security Group.

Copy and execute the key on both servers to join them to the swarm.

To check connected nodes, use the command on the manager node:

docker node ls

🔶 Service Deployment: Deploy the web application as a Docker service in the Swarm cluster. Define the desired number of replicas for horizontal scaling:

docker service create --name todo-app --replicas 3 -p 8000:8000 pmgoriya/pankaj:latest

Use the command to verify the deployment:

docker service ls

Use the command to verify running containers:

docker ps

Now, the service is running on all three nodes. To verify, navigate to http:/<ec2-instance-public-ip-address:8000 using each instance's IP address.

Manager Node:

Worker Node-1:

Worker Node-2:

🔶 To Remove Service: When removing the service and leaving the Swarm, use the following command from any worker node:

docker swarm leave

Verify the node status using:

docker node ls


Thanks for following the project. See you in the next one.