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
Subscribe to my newsletter
Read articles from Kishor Chavan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Kishor Chavan
Kishor Chavan
With a rich history spanning decades in Industrial IT, I currently serve as a Technical Consultant at onshore. My career has been defined by my unwavering commitment to DevOps and leadership in database administration projects. Cloud Expertise: I possess extensive knowledge and hands-on experience in the realms of Microsoft Azure and AWS Cloud. I've played a pivotal role in architecting and optimizing cloud solutions that enable businesses to scale, innovate, and thrive. Cloud DB and DevOps Advocate: My pursuit of excellence never stops. I'm on a constant quest to acquire deep knowledge in Cloud Database solutions and DevOps tools. From Azure DevOps to Jenkins, Ansible to GitHub, Terraform to Docker and Kubernetes, I'm committed to staying at the forefront of industry trends. I'm passionate about leveraging technology to drive success in industrial IT. Let's connect and explore how my decades of experience and expertise can contribute to your organization's growth and transformation.