Kubernetes From Zero to Hero – Part 5: Deployments, ReplicaSets & Scaling Your Applications

Manas UpadhyayManas Upadhyay
3 min read

A Quick Recap

In our previous blog, we explored:

  • The Pod Lifecycle and common states like Pending, Running, CrashLoopBackOff

  • Real-time debugging using kubectl describe, logs, and exec

  • How to simulate pod failures and investigate them

  • Tools and commands to effectively troubleshoot pods

That gave us the skills to manage and debug a single instance of our app. But modern apps rarely run with a single pod. What if it crashes? What if you need to scale?

That’s where today’s concepts come in — Deployments and ReplicaSets.


What is a Deployment?

A Deployment is a higher-level Kubernetes object that manages Pods for you.

It provides:

  • Declarative updates (change state with YAML)

  • Self-healing (if pod crashes, it recreates)

  • Scaling (manually or auto)

  • Rolling updates (zero downtime app updates)

You don’t create Pods directly in production—you use Deployments.


Behind the Scenes: Deployments & ReplicaSets

A Deployment creates a ReplicaSet, and that ReplicaSet manages the actual Pods.

Hierarchy: (Other Words we say Ranking)

Deployment  ReplicaSet  Pod

Each ReplicaSet ensures the right number of identical Pods are running.


Sample Deployment YAML

Let’s write a simple Nginx Deployment with 3 replicas.

nginx-deployment.yaml

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

Apply it:

kubectl apply -f nginx-deployment.yaml

Explore What Happened

Check Deployments

kubectl get deployments

Check ReplicaSets

kubectl get rs

Check Pods

kubectl get pods -l app=nginx

You should see 3 pods running.


Scaling the Deployment

Need to increase capacity?

kubectl scale deployment nginx-deployment --replicas=5

Need to decrease?

kubectl scale deployment nginx-deployment --replicas=2

Rolling Updates in Action

Let’s update the Nginx version.

kubectl set image deployment/nginx-deployment nginx=nginx:1.21.0

Watch the rollout:

kubectl rollout status deployment/nginx-deployment

Check history:

kubectl rollout history deployment/nginx-deployment

Rollback if needed:

kubectl rollout undo deployment/nginx-deployment

Self-Healing in Action

Delete one pod:

kubectl delete pod <pod-name>

Run:

kubectl get pods

Kubernetes will automatically recreate the deleted pod to maintain the replica count.


Bonus: Autoscaling with HPA

You can even autoscale deployments based on CPU usage:

kubectl autoscale deployment nginx-deployment --cpu-percent=50 --min=2 --max=10

We’ll dive deeper into HPA (Horizontal Pod Autoscaler) in a future post.


Cleanup

To delete the deployment:

kubectl delete deployment nginx-deployment

This also deletes the ReplicaSet and all its pods.


What’s Next?

In the next blog, we’ll:

  • Expose your app externally using a Service

  • Understand ClusterIP, NodePort, and LoadBalancer

  • Setup Ingress controllers for clean URL routing

0
Subscribe to my newsletter

Read articles from Manas Upadhyay directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Manas Upadhyay
Manas Upadhyay

I am an experienced AWS Cloud and DevOps Architect with a strong background in designing, deploying, and managing cloud infrastructure using modern automation tools and cloud-native technologies.