Project 4-Devops
Project Description
The objective of this endeavor is to implement a web application through Docker Swarm, a robust container orchestration tool designed for efficient management and scalability of container-based applications. Leveraging Docker Swarm's comprehensive features tailored for production environments—such as load balancing, seamless updates, and service discovery—the aim is to uphold the web application's reliability and availability. This initiative entails crafting a Dockerfile to encapsulate the application within a container, followed by deployment onto a Swarm cluster. The Swarm cluster will be meticulously configured to facilitate automated failover, load balancing, and horizontal scaling for the application. Ultimately, the project seeks to showcase Docker Swarm's prowess in deploying and overseeing containerized applications within real-world production settings.
Step 1:
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 update
sudo apt install docker -y
sudo apt install docker-compose
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker ubuntu
sudo reboot
Our all three instances are up and ready to configure.
Step -2: Establishing a Docker Swarm Cluster:
Will Connect to DS-Manger instance node (main node) and create a Docker Swarm cluster with multiple nodes for managing deployed containers using "docker swarm init " command. Make sure you are opened port 2377 in security group.
Step -3: To add worker node connect to other 2 ec2 instance run docker swarm join command.
To verify worker node and manager node will execute docker node ls command on manager node.
Step 4: Deploy the web application as a Docker service in the Swarm cluster make sure the desired number of replicas for horizontal scaling
docker service create --name todo-app --replicas 3 -p 8000:8000 kishorchavan87/todo-app:latest
We could see that service deployed on all three node. let's verify container deployment on all nodes using navigate public ip:8000
We are abele to access. Code with all three node..
Step 5: To Remove Service: When removing the service and leaving the Swarm, use the command "Docker swarm leave" from any worker node.
We can see worker node are down now.
Let's remove service from manager node to completely destroy deployment.
docker service ls #List all active service
docker service rm service_id #Remoove service
I hope this article is helpful to understand docker swarm concept.
Thanks for reading !
Thanks,
Kishor Chavan