Djyango Todo-app Deployment In Kubernetes
I have written this article for college miniproject.
PROBLEM STATEMENT
Here we are deploying the Todo app using GitHub, Docker, and AWS in Kubernetes.
DETAILED REQUIREMENT
Dockerfile
Docker-Image
AWS credential
AWS CLI
Deployment. yaml
Service. yaml
SOFTWARE TOOL USED
- Github
GitHub is a web-based platform that provides a hosting service for Git repositories. It allows individuals and teams to collaborate on projects by providing version control functionality and tools for managing code repositories.
- Docker
Docker is an open-source platform that enables developers to automate the deployment and management of applications within lightweight, isolated containers
- Docker Registry
A Docker registry is a central repository for storing and distributing Docker images..
- AWS
AWS stands for Amazon Web Services. It is a comprehensive cloud computing platform provided by Amazon. AWS offers a broad range of cloud services and solutions.
- Minikube
Minikube is a tool that allows you to run a single-node Kubernetes cluster locally on your machine.
TOTAL MAN HOUR AND WORK
After solving lots of errors and I came up with a DevOps project for the Todo-app Deployment in Kubernetes. It took around 30 hours means around 8 to 10 days.
PROPOSED SOLUTION, DESIGN, IMPLEMENTATION AND CODE
- CREATE DOCKER FILE
FROM python:3
RUN pip install django==3.2
COPY . .
RUN python manage.py migrate
EXPOSE 8001
CMD ["python","manage.py","runserver","0.0.0.0:8001"]
- Build the Docker image.
Use the docker build
command to build the Docker image from the Dockerfile.
docker build -t todo-app:latest .
Push the Docker image to a container registry
docker push anish60/project:latest
- Create Deployment
In Kubernetes, a Deployment is an object that provides declarative updates and lifecycle management for Pods and ReplicaSets. It is a higher-level abstraction that simplifies the process of managing and scaling application deployments.
apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-deployment
labels:
app: todo
spec:
replicas: 3
selector:
matchLabels:
app: todo
template:
metadata:
labels:
app: todo
spec:
containers:
- name: todo
image: anish60/project:latest
ports:
- containerPort: 8001
Run command kubectl apply -f deployment.yaml
- Create service of NodePort
In Kubernetes, a Service is an abstract layer that provides network connectivity and load balancing to a set of Pods.
apiVersion: v1
kind: Service
metadata:
name: todo-service
spec:
type: NodePort
selector:
app: todo
ports:
- port: 8001
targetPort: 8001
nodePort: 30007
Run Command kubectl apply -f service.yaml
Now we have to expose our deployment and forward the service port to AWS Ec2 to access our application.
kubectl expose deployment <deployment-name> --NodePort
kubectl port-forward svc/<service-name> 8001:8001 --address 0.0.0.0 &
Now, Access your Application on http://<ec2_public_ip>:8001
Conclusion
This DevOps project can be added to Resume too. This is a real demonstration that how big companies deploy their application in Kubernetes and there is a lot of service that Kubernetes provide.