Day 83 - Project-4

Day 83 - Project-4

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-01

Deploying web application using docker swarm

Step -1

  • Open your AWS management console and launch 2 EC2 instances, which we will call Master and Worker nodes.

  • Now install docker and docker-compose in the Master and Worker nodes.
sudo apt install docker.io -y && sudo apt install docker-compose -y && sudo chown $USER /var/run/docker.sock

Step-2

  • Now we will set up the Docker Swarm cluster on the master and worker nodes.

In Master node use this

docker swarm init

In the Worker node use this

  • Open your Master's instance security group and enable port number 2377.

  • From the Master node, copy the Docker Swarm join token and paste it in the Worker node.

  • To verify the connected worker nodes and manager nodes in the Docker swarm, you can use the command
docker node ls

Step-3

  • Now we will deploy the web application. We will deploy the Django application by cloning it using this command:
git clone https://github.com/nallabellisriparthu/django-todo-cicd.git && ls

  • Now build your application using the commands below.
docker build -t django-todo-cicd .

  • Now, in your master instance, log in to Docker Hub and tag, and push into your Docker Hub using the command below.
docker login

docker tag <your application name> <dockerhub username>/<your application name>

docker push nsparthu/django-todo-cicd

Step-4

  • Now it's time to deploy your web application using the Docker image stored on DockerHub. Use the following command to deploy the application as a service on the Swarm:
docker service create --name <your application name> --replicas <your replica number> -p <your port number>:<you port number> <your dockerhub username>/<your application name>:latest

  • Once the service is deployed, you can verify its status and check if the desired number of replicas are running on the Swarm nodes. Use the following commands to see the running services
docker service ls && docker ps

  • Now enable port number 8000 in the master node.

  • To verify the connected worker nodes and manager nodes in the Docker swarm, you can use the command:
docker node ls

Step-5

  • Now, the service is running on all 2 nodes. To verify this, navigate to http://<ec2-instance-public-ip-address>:8000 using every instance IP Address.

Master

Worker

Step-6

  • When you are done with the project, you can remove the service and leave the Swarm. To remove the service, use the following command from any worker node:
docker swarm leave

  • After removing one of the workers, we can observe its status as "down" within the status information.
docker node ls

  • To leave the Swarm, run the following command on the manager node:
docker swarm leave --force


Happy Learning

Thanks For Reading! :)

-DevOpsParthu💝💥