Catalog My learning Blog
Docker and Kubernetes Tutorial: Containers to Production · Phase 4 · Lesson 27 · 4 min read

Rolling vs Blue-Green vs Canary Deployments

On this page
  1. Rolling update vs blue-green vs canary
  2. What zero-downtime deploys require from your app
  3. Blue-green deployments on Kubernetes
  4. Canary releases gated on metrics with Argo Rollouts
  5. How to make rollback fast and boring
  6. Check yourself

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 updateBlue-greenCanary
HowReplace Pods graduallyRun the new version fully beside the old, switch all traffic at onceSend a small share of traffic to the new version, increase step by step
Old and new run togetherYes, during the rolloutBriefly, without serving at the same timeYes, deliberately
Users exposed to a bad versionGrowing share until noticedAll, from the switch until rollbackOnly the canary share
RollbackAnother rolling updateSwitch traffic back: secondsSet canary weight to zero
Extra capacityA little (maxSurge)Double, during the releaseA little
ToolingBuilt into DeploymentsTwo Deployments plus a Service or route switchGateway or mesh traffic splitting, often Argo Rollouts or Flagger
A rolling update replaces Pods gradually, blue-green switches all traffic between two full environments, and a canary shifts a growing share of traffic to the new version.
A rolling update replaces Pods gradually, blue-green switches all traffic between two full environments, and a canary shifts a growing share of traffic to the new version.

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 short preStop sleep (a few seconds) so load balancers stop sending traffic before the app stops listening. Distroless images have no sleep binary, so use the built-in lifecycle.preStop.sleep.seconds action, on by default since Kubernetes 1.30. Do the arithmetic, too: the preStop time counts against terminationGracePeriodSeconds (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:

YAML
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 propagates

Blue-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:

YAML
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.