Deploying a Django Todo App:

Deploying a Django Todo App:

Before we begin, make sure you have the following prerequisites:

  1. An AWS account with an EC2 instance running.

  2. kubectl and kubeadm installed on your local machine.

  3. The Django Todo app source code from GitHub.

Step 1: Clone the Repository

Clone the Django Todo app repository to your local machine:

git clone https://github.com/Rohit123890/django-todo-cicd.git
cd django-todo-cicd

Step 2: Create Docker Images

Dockerize the Django Todo. Make sure you have Docker installed on your machine.

# Build the image
docker build -t django-todo .

Step 3: Push Images to Docker Hub

To deploy the image in your AWS EC2 Kubernetes cluster, you'll need to push it to a container registry. Docker Hub is a popular choice.

docker login
docker push yourusername/django-todo

Step 4: Set Up Kubernetes Cluster on EC2

4.1. Install kubeadm, kubelet, and kubectl on the EC2 instance.

SSH into your EC2 instance and install the required Kubernetes tools.

sudo apt-get update && sudo apt-get install -y kubeadm kubelet kubectl

4.2. Initialize Kubernetes Master

On the EC2 instance, run the following command to initialize the Kubernetes master node.

sudo kubeadm init

4.3. Set Up kubectl

Copy the Kubernetes configuration to your home directory.

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Step 5: Deploy the Django Todo App

Deploy using a Kubernetes deployment.

kubectl apply -f .

Step 6: Access the Django Todo App

Find the external IP address of your EC2 instance:

kubectl get nodes -o wide

Access the Django Todo app using the external IP and port 30080 (NodePort):

http://<external-ip>:30080

Conclusion

Congratulations! You have successfully deployed a Django Todo app on an AWS EC2 instance using a Kubernetes cluster created with Kubeadm. This project demonstrates the power of Kubernetes for managing and scaling containerized applications in a cloud environment.