Project-9: ๐ Setting up a Kubernetes Cluster with MiniKube on AWS: Deploying Django Todo App and Managing Network and Services ๐
Section 1: Setting up a Kubernetes Cluster with MiniKube on AWS ๐
Why MiniKube?
MiniKube is a fantastic lightweight tool that lets you run Kubernetes on your local machine. It's perfect for development, testing, and learning purposes. With MiniKube, you can quickly and easily set up a Kubernetes environment without the hassle of a complex setup. It's especially great for developers who want to experiment with Kubernetes.
๐ How to Install MiniKube on Your Local Machine ๐
Launch an EC2 instance:
Log in to your AWS account and click "Launch Instance."
Choose an Ubuntu Server AMI and select t2.medium with 4GB RAM and 2 CPU.
Connect to your EC2 instance:
- Use SSH to connect to your instance:
ssh -i <key-pair>.pem ubuntu@<public-IP-address>
- Use SSH to connect to your instance:
Install Docker:
- Update your instance and install Docker:
sudo apt-get update
sudo apt-get install docker.io
sudo systemctl start docker
Install MiniKube:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local/bin/minikube
Start MiniKube:
minikube start --driver=docker
Verify MiniKube:
kubectl version
Section 2: Deploying Django Todo App in Kubernetes Pods and Managing Cluster ๐
Role of Docker Containers and Kubernetes Pods
Docker Containers package applications and their dependencies for easy deployment. In this project, we use Docker Containers to package our Django Todo app. Kubernetes Pods are the smallest units in a cluster, encapsulating one or more containers and shared resources.
โ๏ธ Importance of Deployment, Replication, Auto-Healing, and Auto-Scaling in Kubernetes โ๏ธ
Deployment: Defines the desired state and management of your application, ensuring the right number of replicas with minimal downtime.
Replication: Maintains a specified number of Pod replicas, ensuring high availability and fault tolerance.
Auto-healing: Automatically detects and recovers from failures, ensuring Pods are always running.
Auto-scaling: Automatically adjusts the number of replicas based on demand, handling increased traffic.
๐ Steps to Manage Features for Your Kubernetes Cluster ๐
Clone the django-todo-cicd repository from GitHub.
Build the Docker image:
docker build -t django-todo-cicd:latest . docker run -d -p 8000:8000 django-todo-cicd:latest
Create a Kubernetes Service:
- Create
service.yaml
:
- Create
apiVersion: v1
kind: Service
metadata:
name: todo-service
spec:
type: NodePort
selector:
app: todo-app
ports:
- name: http
port: 80
targetPort: 8000
nodePort: 30007
- Apply the Service:
kubectl apply -f service.yaml
Create a Kubernetes Deployment:
- Create
deployment.yaml
:
- Create
apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-deployment
labels:
app: todo-app
spec:
replicas: 2
selector:
matchLabels:
app: todo-app
template:
metadata:
labels:
app: todo-app
spec:
containers:
- name: todo-app
image: django-todo-cicd:latest
ports:
- containerPort: 8000
Apply the Deployment:
kubectl apply -f deployment.yaml
Verify Pods and Test Auto-healing and Auto-scaling:
kubectl get pods kubectl delete pod todo-deployment-7987844987-88mng (to test auto-healing) kubectl scale deployment todo-deployment --replicas=4 (to test auto-scaling) kubectl get deployments kubectl get pods
Section 3: Managing Network and Services with Host IP Allocation through Proxy on AWS EC2 ๐
Importance of Managing Network and Services
Properly managing network and services in Kubernetes enables seamless communication between applications, both within and outside the Cluster. It ensures high availability, scalability, and security.
๐ Managing Network and Services with Host IP Allocation through Proxy on AWS EC2 ๐
Expose the Pod as a Service:
- Create
service.yaml
:
- Create
apiVersion: v1
kind: Service
metadata:
name: todo-service
labels:
app: todo-app
spec:
type: NodePort
selector:
app: todo-app
ports:
- name: http
port: 80
targetPort: 8000
nodePort: 30007
- Apply the Service:
kubectl apply -f service.yaml
Map the IP address to a hostname:
- Edit the /etc/hosts file:
sudo vim /etc/hosts
- Add a new line:
<Node-IP>
todo-app.com
- Access the Django Todo app using the URL
http://todo-app.com
in a web browser.
Congratulations! with these steps you will successfully set up and deployed a Django Todo app on a Kubernetes cluster using MiniKube and managed its network and services on AWS EC2 with Route53!
Conclusion ๐ฏ
In this project, we covered the essential steps to create a Kubernetes cluster using MiniKube on AWS EC2, deployed a Django Todo app in Kubernetes Pods, and managed the network and services through AWS EC2. By understanding these concepts, you are now equipped to explore more complex applications and unleash the full power of Kubernetes in your projects! Happy coding! ๐๐
Subscribe to my newsletter
Read articles from Pooja Bhavani directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by