Skip to main content

Command Palette

Search for a command to run...

Day 32 Task: Launching your Kubernetes Cluster with Deployment

Published
2 min read
Day 32 Task: Launching your Kubernetes Cluster with Deployment
A

"I'm a 3rd-year Computer Engineering student at Marwadi University with skills in C++, web development (MERN stack), and DevOps tools like Kubernetes. I contribute to open-source projects and share tech knowledge on GitHub and LinkedIn. I'm learning cloud technologies and app deployment. As an Internshala Student Partner, I help others find jobs and courses." now currently focusing on #90DaysOfDevops

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:

  1. Clone the repository for your application:

      git clone https://github.com/anand-raval-git/django-todo.git
    
  2. 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 .
    
  3. Push the Docker image to DockerHub:

     docker login
     docker push anandraval12/django-todo-app:latest
    
  4. 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
    
  5. Apply the Deployment to your Kubernetes (Minikube) cluster:

      kubectl apply -f deployment.yml
    

  6. Verify the Pods are running:

      kubectl get pods
    

  7. Test the application on the worker node:

      docker ps
      sudo docker exec -it <docker-container> bash
      curl -L http://127.0.0.1:8000
    
  8. Test Auto-healing by deleting a Pod and ensuring a new one is created:

     kubectl delete pod <pod-name>
    
  9. Delete the Deployment when done:

     kubectl delete -f deployment.yml
    

Thankyou for reading !!!!!!

90DaysOfDevops

Part 14 of 49

So In This Series I am following 90 DaysOfDevops challenge , what i will learn in my devops journey i will share with you with my blogs ,You will get blog on tools which used by devops engineer , example :- Linux,ansible,terraform,docker,etc

Up next

Day 31 Task: Launching Your First Kubernetes Cluster with Nginx Running 🌐

What about doing some hands-on now? Let's read about minikube and implement k8s in our local machine What is minikube? Ans:- Minikube is a tool which quickly sets up a local Kubernetes cluster on macOS, Linux, and Windows. It can deploy as a VM, a...

More from this blog

A

Anand Raval

118 posts

Hello I am Anand Raval , i contributed my work in robotics(arduino uno) , fronted web devloper,competitive programming, now currently focusing on #90DaysOfDevops