0Pricing
DevOps Bootcamp · Lesson

Rolling Updates and Rollbacks

Implement zero-downtime application updates and revert to previous versions if issues arise.

Rolling Updates and Rollbacks is a free DevOps Bootcamp lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Zero-Downtime Updates: Why?

Imagine updating a live application. Without careful planning, users might experience downtime or errors. This is where rolling updates in Kubernetes shine!

Rolling updates allow you to update your application to a new version without interrupting service. New versions are gradually rolled out, ensuring your app stays available.

How Deployments Handle Updates

When you update a Deployment's Pod template (e.g., changing the container image), Kubernetes doesn't just shut down everything and restart. Instead, it uses a RollingUpdate strategy by default.

  • It creates new Pods with the updated configuration.
  • It gradually terminates old Pods once the new ones are ready.
  • This process ensures a smooth transition with minimal to no downtime.

Controlling the Rollout Speed

You can fine-tune how rolling updates behave using two key parameters in your Deployment's .spec.strategy.rollingUpdate section:

  • maxUnavailable: The maximum number of Pods that can be unavailable during the update. Can be an absolute number or percentage.
  • maxSurge: The maximum number of Pods that can be created over the desired number of Pods. Also an absolute number or percentage.

By default, both are set to 25%.

Our Initial Deployment

Let's start with a simple Nginx deployment. This YAML defines our initial application running 3 replicas of nginx:1.14.2.

We'll use this as our base to perform a rolling update in the next step.

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

Performing a Rolling Update

Now, let's update our Nginx version from 1.14.2 to 1.15.0. We simply change the image in the YAML and apply it.

Kubernetes will detect the change and initiate a rolling update automatically. Observe the image field below:

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

Monitoring the Rollout Status

After applying the updated YAML, you can monitor the progress of your rolling update using the kubectl rollout status command:

kubectl rollout status deployment/my-nginx

You'll see messages indicating new Pods being created and old ones being terminated until the update is complete. You can also use kubectl get rs to see the old and new ReplicaSets.

Checking Rollout History

Kubernetes keeps a history of your Deployments' revisions. This is incredibly useful for understanding changes and for potential rollbacks.

To see the history, use the command:

kubectl rollout history deployment/my-nginx

You'll see a list of revisions, each representing a distinct state of your Deployment. The CHANGE-CAUSE often reflects the command or YAML change.

When a Rollback is Needed

Even with careful testing, sometimes a new application version introduces bugs or performance issues that weren't caught. In such critical situations, you need a quick way to revert to a known stable state.

This is where rollbacks come in. They allow you to undo a problematic update and revert your Deployment to a previous, functional version from its history.

Executing a Rollback

To roll back to the immediately previous revision, use:

kubectl rollout undo deployment/my-nginx

If you want to roll back to a specific revision (e.g., revision 1), you can specify it:

kubectl rollout undo deployment/my-nginx --to-revision=1

Kubernetes will perform another rolling update to revert the Pods to the specified historical configuration.

Rollout Strategy Check

Which of the following parameters can be used to control the behavior of a Kubernetes Deployment's RollingUpdate strategy?

Recap: Smooth Updates & Safety Nets

We've explored how Kubernetes Deployments enable zero-downtime rolling updates, gracefully transitioning your applications to new versions. You learned:

  • Deployments use RollingUpdate by default.
  • maxUnavailable and maxSurge control update speed.
  • kubectl rollout status monitors progress.
  • kubectl rollout history tracks revisions.
  • kubectl rollout undo allows quick rollbacks to stable versions.

These features are crucial for maintaining high availability and reliability in your applications!

Frequently asked questions

Is the “Rolling Updates and Rollbacks” lesson free?

Yes — the full text of “Rolling Updates and Rollbacks” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Rolling Updates and Rollbacks”?

Implement zero-downtime application updates and revert to previous versions if issues arise. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Rolling Updates and Rollbacks” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Understanding Deployments
  2. Scaling Applications with ReplicaSets
  3. Rolling Updates and Rollbacks
  4. Deployment Strategies: Blue-Green and Canary
← Back to DevOps Bootcamp