Day 32 Launching your Kubernetes Cluster with Deployment

Day 32 Launching your Kubernetes Cluster with Deployment

Β·

3 min read

Day 32 of #90daysofdevops

Hey Techies! Welcome to this blog

In this blog, we are going to start with launching your Kubernetes Cluster with Deployment

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

Now, the real fun begins! We'll create a Deployment file to deploy a sample todo-app on Kubernetes with the magical touch of "Auto-healing" and "Auto-Scaling."

open minikube in ec2 :-

let's check the status of Minikube.

Now Clone the repository from GitHub. Github Repo link:-

https://github.com/LondheShubham153/django-todo-cicd.git

build image :-

docker build -t django-todo:latest .

Login to your Docker Hub by using your username and password and push your image to Docker Hub.

docker push kritikashaw/django-todo

check minikube status

minikube status

Add a deployment.yml file

What is Deployment in k8s?

A Deployment provides declarative 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 ReplicaSets or to remove existing Deployments and adopt all their resources with new Deployments.

Here are the key aspects of a Kubernetes Deployment:

  1. Desired State

  2. Rolling Updates and Rollbacks

  3. Scaling

  4. High Availability

  5. Self-healing

Let's start by creating a deployment.yml file. This YAML file contains the configuration details of our deployment. Here's a sneak peek:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: todo-app
  labels:
    app: todo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: todo
  template:
    metadata:
      labels:
        app: todo
    spec:
      containers:
      - name: todo
        image: kritikashaw/django-todo
        ports:
        - containerPort: 8000

Create the deployment using kubectl apply -f deployment.yml

Scale the replicas of deployment if required

Here I have scaled the replicas to 2,

using
kubectl scale --replicas=2 deploy/todo-deployment.yml

That's it! You've just completed the task. πŸŽ‰

Thank you so much for taking the time to read till the end! Hope you found this blog informative and helpful.

Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.

Happy Learning!

~kritika :)

Connect with me: linkedin.com/in/kritikashaw

Β