Launching your Kubernetes Cluster with Deployment

Launching your Kubernetes Cluster with Deployment

Introduction

A Deployment in Kubernetes (K8s) is a crucial resource that orchestrates the deployment and scaling of containerized applications. It offers a declarative approach to specifying the desired state of an application, including the number of instances (replicas) that should be actively running. This ensures applications are always available and responsive to user demands.

What is Deployment in K8s?

A Deployment provides a configuration for updates for Pods and ReplicaSets.

In Kubernetes, a deployment is a resource object that manages the deployment and scaling of a set of containerized applications. It provides a declarative way to define the desired state of an application, including the number of replicas (instances) that should be running.

Key characteristics of a Kubernetes deployment:

  1. Desired State: It ensures that a specified number of replicas of a containerized application are running at any given time.

  2. Rolling Updates: It supports updates to applications without downtime by gradually replacing old pods with new ones.

  3. Rollback: If an update causes issues, a deployment can be rolled back to a previous version.

  4. Scaling: It allows both manual and automatic scaling of the number of replicas to meet demand.

  5. Self-healing: If a pod fails, Kubernetes automatically replaces it to maintain the desired state.

Task-1:

Create a Deployment file to demonstrate deploying an nginx image on K8s, showcasing "Auto-healing" and "Auto-Scaling" features.

Deploying a Simple Nginx Pod in Minikube: Step-by-Step Guide

To set up Minikube locally, refer to my ---> previous blog <--- post for detailed instructions.

Step 1: Start Minikube

minikube start

Step 2: Define a Deployment YAML File

Create a file named deployment.yaml and add the following content:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  namespace: nginx
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      namespace: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80

Step 3: Apply the YAML File

Apply the YAML file to create the deployment:

kubectl apply -f first-deployment.yaml

Step 4: Check the Status of the Deployment

kubectl get deployments -n nginx

2nd and 3rd are pods that are created now

After completing these steps, you will have successfully deployed an Nginx deployment with two replicas and checked its status.

Task-2:

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

Step 1: Clone the Repository from GitHub

Step 2: Build the Image

docker build -t <dockerhub_username>/node-todo:latest .

Step 3: Push the Docker Image to Docker Hub

docker login
docker push <dockerhub_username>/node-todo:latest

Step 4: Add a deployment.yaml File

apiVersion: apps/v1
kind: Deployment
metadata:
  name: todo-deployment
  labels:
    name: todo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: todo
  template:
    metadata:
      labels:
        app: todo
    spec:
      containers:
      - name: todo-container
        image: simbaa815/node-todo:latest
        ports:
        - containerPort: 8000

Step 5: Apply the Deployment to Your K8s (Minikube) Cluster

kubectl apply -f deployment.yaml

Step 6: Get Pods

kubectl get pods

Step 7: Delete a Pod for Testing Auto Healing

kubectl delete pod <pod_name>

As you can see, a new pod will be automatically created, demonstrating the concept of Auto Healing.

Conclusion:

Kubernetes Deployments streamline application management, ensuring seamless updates and scaling.

Stay tuned for more in-depth Kubernetes insights in our upcoming blogs. Keep learning and stay ahead! 🚀


Let's Connect ❤️:

| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|
------- Let's connect! -------
|_____________|
............... \ (•◡•) / ...................
................. \ ...... / .....................
.................. ——- .......................
.................. | ... | ......................
.................. |_ . |_ ....................

Linkedin

GitHub

Twitter

Hashnode

Thank you for exploring my blog!