What is Deployment in k8s
A Deployment provides a configuration for updates for Pods and ReplicaSets.
You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate. You can define Deployments to create new replicas for scaling, or to remove existing Deployments and adopt all their resources with new Deployments.
Task-1:
Create one Deployment file to deploy a sample todo-app on K8s using "Auto-healing" and "Auto-Scaling" feature
add a deployment.yml file (sample is kept in the folder for your reference)
apply the deployment to your k8s (minikube) cluster by command
kubectl apply -f deployment.yml
Deploy a Sample todo-app on Kubernetes
Let’s apply our Deployment configuration:
Clone the repository for your application:
git clone https://github.com/anand-raval-git/django-todo.git
Create a Docker image from your Dockerfile:
# Dockerfile FROM python:3.11 WORKDIR /data RUN pip install django==3.2 COPY . . RUN python manage.py migrate EXPOSE 8000 CMD ["python","manage.py","runserver","0.0.0.0:8000"]
docker build -t anandraval12/django-todo-app .
Push the Docker image to DockerHub:
docker login docker push anandraval12/django-todo-app:latest
Create the Deployment YAML file
Create
deployment.yml
file for deploying a todo-app:apiVersion: apps/v1 kind: Deployment metadata: name: django-todo-deployment namespace: default spec: replicas: 1 selector: matchLabels: app: django-todo template: metadata: labels: app: django-todo spec: containers: - name: django-todo image: anandraval12/django-todo-app:latest ports: - containerPort: 8000
Apply the Deployment to your Kubernetes (Minikube) cluster:
kubectl apply -f deployment.yml
Verify the Pods are running:
kubectl get pods
Test the application on the worker node:
docker ps sudo docker exec -it <docker-container> bash curl -L http://127.0.0.1:8000
Test Auto-healing by deleting a Pod and ensuring a new one is created:
kubectl delete pod <pod-name>
Delete the Deployment when done:
kubectl delete -f deployment.yml
Thankyou for reading !!!!!!