Skip to content
tezvyn:
Menu

Rolling Updates: Deploying Code Without Downtime

Source: kubernetes.ioMediumHow cards are made

Rolling Updates: Deploying Code Without Downtime

A rolling update deploys new code by gradually replacing old application instances with new ones, ensuring zero downtime. It's the default for stateless services in orchestrators like Kubernetes.

Why it exists

Deploying new software versions traditionally required taking the application offline, creating a service outage for users. Rolling updates solve this by enabling zero-downtime deployments, ensuring the service remains available throughout the update process.

The mental model

Think of a rolling update like changing the tires on a moving car, one by one. Instead of stopping the car (the service), you replace each old tire (an application instance) with a new one while the car keeps going. The service never stops, though its capacity might be slightly reduced or increased temporarily.

How it works

A controller, like a Kubernetes Deployment, manages the process. When you trigger an update, it creates a new version of your application's configuration. Then, it gradually scales up the new version while scaling down the old one. For example, it might add one new instance, wait for it to pass its health checks and report "ready," and only then terminate one old instance. This cycle repeats until all old instances are replaced. You can control the speed and resource overhead using two key settings: maxSurge, which allows a certain number of new instances to be created above the desired count, and maxUnavailable, which defines how many old instances can be taken down at once.

When to use it

This is the default and most common deployment strategy for stateless applications, such as web servers, APIs, and microservices. It's ideal when all instances of your application are identical and interchangeable, and when the application can tolerate running a mix of old and new versions temporarily.

When not to use it

Avoid rolling updates when a new code version requires a backwards-incompatible database schema change, as the old and new code versions cannot coexist. It's also not ideal for stateful applications that require careful orchestration or when you need to test a new version on a small subset of traffic first (use a Canary deployment instead). For instant, atomic cutovers, a Blue/Green deployment is a better choice.

One canonical example

In Kubernetes, a Deployment object uses the rolling update strategy by default. If you have a Deployment running 10 pods of my-app:v1 and you update the manifest to use my-app:v2, Kubernetes automatically starts the process. With maxSurge=1 and maxUnavailable=1, it will launch one v2 pod. Once that pod is ready, it will terminate one v1 pod. This continues until all 10 running pods are version v2, all without interrupting service.

Interview question

Which scenario best highlights the primary benefit of a rolling update deployment strategy?

  • a.Testing a new feature with a small percentage of users before full release.
  • b.Instantly switching all user traffic from an old version to a new one.
  • c.Performing a database schema migration that is not backward-compatible.
  • d.Ensuring an application remains accessible to users throughout a version upgrade.Correct
Why?

The primary benefit of a rolling update is to enable zero-downtime deployments, ensuring continuous service availability during an update. While other strategies like Blue/Green (option B) offer instant cutovers, rolling updates focus on maintaining service availability by gradually replacing instances.

Just read this? Test yourself on what you have been reading.

Read the original → kubernetes.io

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on kubernetes — each one lists the topics its interview covers.

See open roles