Launching your Kubernetes Cluster with Deployment

Launching your Kubernetes Cluster with Deployment

It’s #day32 of the #90daysofdevops Challenge under the guidance of Shubham Londhe Sir.

Today I have covered,
- Installation of Minikube cluster.
- How to create a pod, deployment, auto-healing, and auto-scaling.

Why Auto-healing & Auto-Scaling is important?
Auto-healing and Auto-scaling are important because they help keep computer systems running smoothly and efficiently. Auto-healing automatically fixes any problems that arise while auto-scaling makes sure that the system has enough resources to handle changes in demand without crashing.

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.

Before Doing the task let's set up the git repository for the same and push the code to the repository.

Steps to follow: Here we will use AWS for Deployment and Git for version control.

Step-01: Open your terminal or any other cloud service.

Step-02: Update and install Docker on your machine.

sudo apt update
sudo apt install docker.io

Screenshot from 2023-04-17 22-08-47

Screenshot from 2023-04-17 22-15-44

Step-03: Now give Docker permission for super-user of your local machine.

sudo usermod -aG docker $USER && newgrp docker

Screenshot from 2023-04-17 22-24-25

Step-04: Now lets install Minikube.

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

sudo install minikube-linux-amd64 /usr/local/bin/minikube

Screenshot from 2023-04-17 22-19-41

Screenshot from 2023-04-17 22-20-07

Screenshot from 2023-04-17 22-20-36

Step-05: Now let's start Minikube.

minikube start
  • let's connect with docker.
minikube start — driver=docker

Screenshot from 2023-04-17 22-22-18

Screenshot from 2023-04-17 23-06-54

Step-06: Now let's check the status of Minikube.

minikube status

Step-07: Now we will install the Command line instruction for Minikube which is Kubectl.

  • But first, install snap on your machine.
sudo apt install snap

Screenshot from 2023-04-17 23-10-55

  • CLI for Minikube is Kubectl.
sudo snap install kubectl --classic

Screenshot from 2023-04-17 23-12-11

Step-08: Now let's check the version of Kubectl.

kubectl version

Step-09: Now Clone the repository from GitHub. Github Repo link: github.com/LondheShubham153/django-todo-cic..

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

Step-10: Now let's check the files in the repository.

ls
cd django-todo-cicd

Screenshot from 2023-05-05 16-03-41

Step-11: Now let's create a Dockerfile.

vim Dockerfile

Screenshot from 2023-05-05 16-13-54

Step-12: Now let's build the image.

docker build -t rohit8329/django-todo:latest .

Step-13: Now let's create a docker container for checking whether the image is running on port or not.

docker run -d -p 8000:8000 rohit8329/django-todo:latest

Step-14: Now we will push the docker image to the docker hub.

docker login
docker push mizanfirdausi/django-todo:latest

Task-1:

Create one Deployment file to deploy a sample todo-app on K8s using the "Auto-healing" and "Auto-Scaling" features.

Now let's create a Kubernetes pod using the YAML file.

apiVersion: v1

kind: Pod

metadata:

  name: todo-pod

spec:

  containers:

  - name: todo-app

    image: mizanfirdausi/django-todo:latest

    ports:

    - containerPort: 8000

Now let's apply the pod YAML file.

kubectl apply -f todo-pod.yaml

Screenshot from 2023-05-05 19-00-50

Concept:

Auto-Healing: Auto-healing is a feature that allows Kubernetes automatically restart containers that fail for various reasons. It is a very useful feature that helps to keep your applications up and running.

Auto-Scaling: Auto-scaling is a feature that allows Kubernetes automatically scale the number of pods a deployment based on the resource usage of the existing pods.

Screenshot from 2023-05-05 19-53-08

Here on purpose, I have killed the pod to check the auto-healing feature. for Auto-scaling we use a replica set.