Skip to main content

Command Palette

Search for a command to run...

๐Ÿ’กLaunching Your Kubernetes Cluster with Deployment.

Deploy Smarter: Kubernetes Auto-Healing, Scaling & Rollbacks.

Published
โ€ข3 min read
๐Ÿ’กLaunching Your Kubernetes Cluster with Deployment.
A

๐Ÿ‘จโ€๐Ÿ’ป Last-year student diving deep into DevOps, Cloud Engineering, and Infrastructure Automation. Passionate about building scalable, efficient, and secure systems. Letโ€™s connect and build something amazing! ๐Ÿš€


๐Ÿ” What is a Deployment in Kubernetes?

A Deployment helps manage application updates, scaling, and availability by ensuring the desired number of Pods are always running.

โœ… Key Features of Deployments

  • Auto-healing: Restarts crashed Pods automatically.

  • Auto-scaling: Adjusts the number of Pods based on load.

  • Rolling updates: Deploy new versions with zero downtime.

  • Rollback: Revert to a previous version if needed.

๐Ÿ’ก In simple terms: You define how many Pods you want, and Kubernetes ensures they are running and healthy at all times.


๐Ÿ›  Task 1: Deploying a Sample Todo-App with Auto-Healing, Auto-Scaling & Rolling Updates

Letโ€™s deploy a Todo App using a Kubernetes Deployment.

๐Ÿ“„ Step 1: Create a Deployment File (deployment.yml)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: todo-app
  labels:
    app: todo
spec:
  replicas: 3            # Ensures 3 Pods run
  strategy:
    type: RollingUpdate  # Enables rolling updates
    rollingUpdate:
      maxUnavailable: 1  # At most, 1 pod can be unavailable during the update
      maxSurge: 1        # Allows 1 extra pod to start before stopping an old one
  selector:
    matchLabels:
      app: todo
  template:
    metadata:
      labels:
        app: todo
    spec:
      containers:
        - name: todo-container
          image: your-todo-app-image:v1  # Initial version
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: todo-service
spec:
  selector:
    app: todo
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: LoadBalancer

๐Ÿ”น Step 2: Apply the Deployment to Minikube

kubectl apply -f deployment.yml

๐Ÿ” Step 3: Verify Your Deployment

kubectl get pods
kubectl get deployments
kubectl get services

๐Ÿ”„ How Auto-Healing, Auto-Scaling & Rolling Updates Work in This Deployment

๐Ÿ”น Auto-Healing

The Deployment Controller ensures at least 3 replicas are running. If a Pod crashes, it automatically replaces it.

spec:
  replicas: 3  # Ensures 3 instances of the app run

๐Ÿ’ก Example: If one Pod fails, Kubernetes immediately creates a new one to replace it.


๐Ÿ”น Auto-Scaling

You can enable Horizontal Pod Autoscaler (HPA) to automatically adjust the number of Pods based on CPU usage.

Run this command to set up auto-scaling:

kubectl autoscale deployment todo-app --cpu-percent=50 --min=2 --max=5

๐Ÿ’ก Example: If CPU usage goes above 50%, Kubernetes adds more Pods (up to 5). If load decreases, it scales down (minimum 2 Pods).


๐Ÿ”น Rolling Updates (Zero Downtime Deployment)

The RollingUpdate strategy ensures new versions are deployed gradually without downtime.

To update your app from v1 to v2, modify the deployment:

containers:
  - name: todo-container
    image: your-todo-app-image:v2  # New version

Apply the update:

kubectl apply -f deployment.yml

๐Ÿ’ก How it works:
โœ… Kubernetes gradually replaces old Pods with new ones.
โœ… Ensures at least 2 Pods are always running during updates.
โœ… Users donโ€™t experience downtime while the update happens.

Check rollout status:

kubectl rollout status deployment/todo-app

๐Ÿ”น Rollback (Reverting to a Previous Version)

If the new version has issues, rollback to the last stable version with:

kubectl rollout undo deployment todo-app

๐Ÿ’ก How it works:
โœ… Instantly reverts back to the last working version.
โœ… Prevents users from experiencing a broken update.