Day 83 Task: Project-4
Efficiently Deploy, Scale, and Manage Containerized Applications in Production
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.
๐ถ Task: Container Orchestration with Docker Swarm
๐ถ Pre-requisites:
To start, access the AWS portal and set up three new instances with Docker pre-installed.
Use the following shell script and provide it 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
๐ถ Setting Up a Docker Swarm Cluster:
Create a Docker Swarm cluster, consisting of multiple Docker nodes that will manage the deployed containers.
docker swarm init
A Docker Swarm cluster can be established on a single machine for testing or multiple machines for a production-ready setup.
We can see Docker Swarm uses port 2377, so we'll open this port in our Security Group.
Copy and execute this key on both servers to join them to the swarm.
To Check & verify the connected worker nodes and manager nodes in the Docker swarm, We can 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, which allows horizontal scaling to distribute the application's load.
docker service create --name django-node-app --replicas 3 -p 8000:8000 chandreshpatle28/django-todo:latest
Use the below command to verify the Deployment
docker service ls
Use the below command to verify the Running Container.
docker ps
Now, the service is running on all three nodes. To verify this, 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 we need to remove the service and leave the Swarm. To remove the service, use the following command from any worker node:
docker swarm leave
#verify the node gets down or not by using
docker node ls
#To leave the Swarm, run the following command on the manager node:
docker swarm leave --force
๐ถ Benefits and Objectives:
High Availability: Docker Swarm's load balancing and automated failover mechanisms enhance the web application's availability, reducing the risk of service interruptions.
Efficient Scaling: The project demonstrates how Docker Swarm enables horizontal scaling by replicating containers to manage increased traffic.
Reliability: Docker Swarm's automated updates and service discovery capabilities contribute to more reliable application deployment.
Easy Management: Docker Swarm simplifies the management of containerized applications, making it an attractive choice for production environments.
By deploying a web application with Docker Swarm, this project showcases the capabilities of container orchestration in ensuring the high performance and reliability of applications in real-world, production settings.
๐ถ Conclusion:
In conclusion, this project has successfully demonstrated the power and benefits of using Docker Swarm for orchestrating containerized applications in a production environment. Docker Swarm's features and capabilities have been leveraged to deploy a web application with a focus on high availability and efficient management.
Overall, this project serves as a valuable example of how container orchestration tools like Docker Swarm can play a pivotal role in ensuring the success of applications in real-world, production environments. By adopting Docker Swarm, the web application has gained the benefits of high availability, scalability, and automated management, setting the stage for future projects and applications to follow a similar path to success.
Happy Learning :)
Stay in the loop with my latest insights and articles on cloud โ๏ธ and DevOps โพ๏ธ by following me on Hashnode, LinkedIn (https://www.linkedin.com/in/chandreshpatle28/), and GitHub (https://github.com/Chandreshpatle28).
Thank you for reading! Your support means the world to me. Let's keep learning, growing, and making a positive impact in the tech world together.
#Git #Linux Devops #Devopscommunity #90daysofdevopschallenge #python #docker #Jenkins #Kubernetes #Terraform #AWS #Grafana