Introduction

In modern cloud-native applications, deploying updates without affecting users is very important. No one wants their application to go down during a deployment. This is where Kubernetes Rolling Updates help.

Rolling updates in Kubernetes allow you to update your application gradually, without stopping the entire system. Instead of replacing all instances (pods) at once, Kubernetes replaces them step by step, ensuring that some pods are always running and serving users.

In this article, we will understand how rolling updates work in Kubernetes and how to implement them without downtime using simple words, real examples, and best practices.

What is a Rolling Update in Kubernetes?

A rolling update is a deployment strategy in Kubernetes where old pods are replaced by new pods gradually.

This means:

Because of this gradual replacement, users do not experience downtime.

Why Use Rolling Updates?

Rolling updates are widely used in production systems because they provide:

This makes them ideal for microservices and large-scale applications.

How Rolling Updates Work Internally

When you update a deployment:

  1. Kubernetes creates new pods with the updated version

  2. It waits until the new pods are ready

  3. Then it slowly removes old pods

  4. This process continues until all pods are updated

Kubernetes ensures that a minimum number of pods are always available.

Step 1: Create a Deployment

First, create a basic deployment.

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

Apply it:

kubectl apply -f deployment.yaml

This creates 3 running pods.

Step 2: Understand Default Rolling Update Strategy

Kubernetes uses rolling update by default.

You can check it using:

kubectl get deployment my-app -o yaml

You will see:

strategy:
  type: RollingUpdate
  rollingUpdate:
    maxUnavailable: 25%
    maxSurge: 25%

Explanation:

Step 3: Update the Application Image

Now update the application version.

kubectl set image deployment/my-app my-app=nginx:1.22

Kubernetes will automatically start the rolling update.

Step 4: Monitor the Rolling Update

You can watch the update process in real time.

kubectl rollout status deployment/my-app

Or:

kubectl get pods

You will see new pods being created and old pods being terminated gradually.

Step 5: Ensure Zero Downtime with Readiness Probe

To avoid downtime, use readiness probes.

readinessProbe:
  httpGet:
    path: /
    port: 80
  initialDelaySeconds: 5
  periodSeconds: 10

Explanation:

This ensures users do not hit broken pods.

Step 6: Configure Rolling Update Strategy

You can customize rolling updates.

strategy:
  type: RollingUpdate
  rollingUpdate:
    maxUnavailable: 1
    maxSurge: 1

Explanation:

This gives more control over deployment.

Step 7: Rollback if Something Goes Wrong

If the update fails, you can rollback.

kubectl rollout undo deployment/my-app

Kubernetes will restore the previous version.

Step 8: Use Health Checks for Stability

Use both readiness and liveness probes.

livenessProbe:
  httpGet:
    path: /
    port: 80
  initialDelaySeconds: 10
  periodSeconds: 15

Best Practices for Rolling Updates

Common Mistakes to Avoid

Real-World Use Cases

Summary

Rolling updates in Kubernetes allow you to deploy new versions of your application without downtime by gradually replacing old pods with new ones. With proper configuration like readiness probes, controlled update strategy, and monitoring, you can ensure smooth, reliable, and production-ready deployments. This makes Kubernetes a powerful platform for modern DevOps and cloud-native development.