This guide walks through the process of deploying a Django Todo application on AWS EC2 using a Kubernetes cluster set up with Kubeadm. We'll cover everything from initial EC2 setup to final deployment verification.
Prerequisites
AWS Account with EC2 access
Basic knowledge of Docker and Kubernetes
Familiarity with Django applications
Step 1: Create an EC2 Instance
Launch a new EC2 instance in the AWS Console:
Choose Ubuntu Server
Select t2.large instance type for adequate resources
Configure security group to allow inbound traffic on ports:
22 (SSH)
80 (HTTP)
30007 (Application port)
Launch the instance and save the key pair
Step 2: Clone Required Repositories
Connect to your EC2 instance and clone the necessary repositories:
git clone https://github.com/SlayerK15/Scripts.git
git clone https://github.com/LondheShubham153/django-todo-cicd.git
Step 3: Install Docker and Prerequisites
- Navigate to the Scripts directory and make the installation scripts executable:
cd Scripts
chmod 700 *.sh
- Run the Docker installation script:
sudo ./installdocker.sh
Step 4: Install Kubernetes (K8s)
- Execute the Kubernetes installation script:
sudo ./installk8s.sh
This script installs:
kubectl
kubelet
kubeadm
Other Kubernetes prerequisites
Step 5: Set Up Kubernetes Cluster
- Initialize the Kubernetes cluster using kubeadm:
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
- Configure kubectl for the current user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
- Install Calico network plugin:
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Step 6: Deploy the Application
- Apply the necessary Kubernetes configurations:
kubectl apply -f MYSQL-DB/secret.yml
kubectl apply -f MYSQL-DB/configMap.yml
kubectl apply -f MYSQL-DB/deployment.yml
kubectl apply -f deployment.yml
kubectl apply -f service.yml
Step 7: Verify Deployment
- Check the status of all resources:
kubectl get all
verify that:
All pods are in "Running" state
Deployments show desired number of replicas
Services are properly created with assigned cluster IPs
- Access the application:
Use your EC2 instance's public IP with port 30007
Example: http://:30007/todos/
Troubleshooting Tips
- If pods aren't running, check logs:
kubectl logs <pod-name>
- For service issues, verify endpoints:
kubectl get endpoints
- Check events for any errors:
kubectl get events --sort-by='.metadata.creationTimestamp'
Conclusion
You now have a fully functional Django Todo application running on a Kubernetes cluster in AWS EC2. This setup provides:
Container orchestration with Kubernetes
Auto-healing capabilities
Scalability options
Easy management of deployments
Remember to clean up AWS resources when done to avoid unnecessary charges.
Happy Learning! ๐