Rolling vs Blue-Green vs Canary Deployments
On this page
Rolling update vs blue-green vs canary
Every release risks breaking something. The strategy decides how many users see a bad version, for how long, and how fast you can get back.
| Rolling update | Blue-green | Canary | |
|---|---|---|---|
| How | Replace Pods gradually | Run the new version fully beside the old, switch all traffic at once | Send a small share of traffic to the new version, increase step by step |
| Old and new run together | Yes, during the rollout | Briefly, without serving at the same time | Yes, deliberately |
| Users exposed to a bad version | Growing share until noticed | All, from the switch until rollback | Only the canary share |
| Rollback | Another rolling update | Switch traffic back: seconds | Set canary weight to zero |
| Extra capacity | A little (maxSurge) | Double, during the release | A little |
| Tooling | Built into Deployments | Two Deployments plus a Service or route switch | Gateway or mesh traffic splitting, often Argo Rollouts or Flagger |
What zero-downtime deploys require from your app
Whatever the strategy, these must hold or users see errors during deploys:
- Readiness probes, so traffic only reaches Pods that are ready (Day 18).
- Graceful shutdown: on SIGTERM, stop taking new requests, finish in-flight ones, then exit within
terminationGracePeriodSeconds. Because endpoint removal propagates asynchronously, many teams add a shortpreStopsleep (a few seconds) so load balancers stop sending traffic before the app stops listening. Distroless images have nosleepbinary, so use the built-inlifecycle.preStop.sleep.secondsaction, on by default since Kubernetes 1.30. Do the arithmetic, too: the preStop time counts againstterminationGracePeriodSeconds(30 seconds by default), and ASP.NET Core also waits up to 30 seconds by default for in-flight work, so with a 5-second sleep raise the grace period or the app is killed mid-shutdown. - Backward-compatible changes: old and new versions run side by side, so APIs, message formats and database schemas must work for both. Expand first, contract in a later release.
- Enough replicas and a PodDisruptionBudget, so a rollout or node drain never takes too many Pods away at once (Day 18).
Put together in the orders API's Pod template:
spec:
terminationGracePeriodSeconds: 45 # 5 s pause + up to 30 s ASP.NET Core shutdown + margin
containers:
- name: api
image: ghcr.io/myorg/orders-api:1.4.3
lifecycle:
preStop:
sleep: { seconds: 5 } # keep serving while endpoint removal propagatesBlue-green deployments on Kubernetes
Run orders-api-blue (current) and orders-api-green (new) as two Deployments. The Service selects version: blue. Test green directly, then change the Service selector to version: green; all traffic switches at once. Rolling back means switching the selector back. The switch itself is one command, kubectl patch service orders-api -p '{"spec":{"selector":{"app":"orders-api","version":"green"}}}', or with GitOps a one-line change in git. You pay for double capacity during the release.
Canary releases gated on metrics with Argo Rollouts
With the Gateway API (Day 23), a canary is a weighted route. Tools like Argo Rollouts or Flagger automate the steps and check metrics between them:
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: orders-api
spec:
replicas: 6
selector:
matchLabels: { app: orders-api }
template:
metadata:
labels: { app: orders-api }
spec:
containers:
- name: api
image: ghcr.io/myorg/orders-api:1.4.3
strategy:
canary:
steps:
- setWeight: 5
- pause: { duration: 10m }
- analysis:
templates: [{ templateName: error-rate-below-1-percent }]
- setWeight: 25
- pause: { duration: 10m }
- setWeight: 50
- pause: { duration: 10m }At each step, an analysis queries Prometheus for the canary's error rate and latency. If they cross thresholds, the rollout aborts automatically and traffic returns to the stable version, often before anyone is paged.
How to make rollback fast and boring
- Keep the previous version deployable at all times (Deployment revisions, Helm history, the previous image tag in git).
- Practice rollback, so nobody learns the command during an incident.
- Decouple deploy from release with feature flags: ship code dark, enable it gradually, and turn it off without a deploy.
Check yourself
A canary release. A small share of traffic, say 5 percent, goes to the new version first; tools like Argo Rollouts check its error rate and latency, then increase the share step by step, or abort and roll back automatically if the metrics degrade. Most users never see a bad version.
Old and new versions run at the same time against the same database, so a change that breaks the old version causes errors mid-rollout.
When a Pod is terminating, its removal from Service endpoints and load balancers happens asynchronously, so traffic can still arrive for a few seconds. A short sleep in a preStop hook keeps the app serving during that window before it receives SIGTERM, which avoids dropped requests on every deploy.
When you need to switch all traffic at once, for example because two versions can't safely run side by side, or when you want a fully tested environment ready before switching. It needs double capacity during the switch but makes rollback a single change.
Immutable, versioned images, manifests in git, a deployment tool that can redeploy the previous version in one step, backward-compatible database changes, and practice. If rolling back requires a rebuild or manual steps, it'll be slow under pressure.