Deployment strategies

Mid-level Frequently asked 5 min

On this page

The question

What is the difference between a rolling update, a blue/green deployment and a canary release?

30-second answer

A rolling update, the Deployment default, replaces Pods a few at a time, bounded by maxSurge and maxUnavailable, so it needs little extra capacity but v1 and v2 serve together for a while. Blue/green runs the new version as a full second copy, tests it, then switches all traffic at once; rollback is switching back, at the cost of double capacity. A canary sends a small share of traffic to the new version, checks its metrics, and widens step by step, so a bad release reaches few users.

Understand it

Rolling, blue/green and canary

Compare

The Deployment default. Pods are replaced a few at a time, each new one taking traffic once ready, so the split follows the Pod count and versions mix.

View as text

Three facts, how to roll back, the extra capacity needed and whether versions mix, above five moments of a release from v1 to v2. At each moment a bar shows the share of traffic v1 and v2 receive.

Rolling: Rollback: another rollout, gradual. Extra: 1 Pod, maxSurge. Mixed: v1 and v2 serve together. Traffic to v2 over time: start 0%, 1 of 4 25%, 2 of 4 50%, 3 of 4 75%, done 100%. The Deployment default. Pods are replaced a few at a time, each new one taking traffic once ready, so the split follows the Pod count and versions mix.

Blue/green: Rollback: switch back, instant. Extra: a full second copy. Mixed: never: one switch. Traffic to v2 over time: start 0%, green up 0%, tested 0%, switch 100%, done 100%. Green, v2, runs beside blue at full size and is tested without live traffic. One switch, such as a Service selector, moves all traffic; switching back is the rollback.

Canary: Rollback: send 0% to v2. Extra: a few Pods. Mixed: yes, on purpose. Traffic to v2 over time: start 0%, canary 5%, metrics OK 25%, half 50%, done 100%. v2 first gets 5% of traffic while its errors and latency are compared to v1’s. Each step goes ahead only if metrics stay healthy; a bad canary hurts few users.

Three facts, how to roll back, the extra capacity needed and whether versions mix, above five moments of a release from v1 to v2. At each moment a bar shows the share of traffic v1 and v2 receive.

Rolling: Rollback: another rollout, gradual. Extra: 1 Pod, maxSurge. Mixed: v1 and v2 serve together. Traffic to v2 over time: start 0%, 1 of 4 25%, 2 of 4 50%, 3 of 4 75%, done 100%. The Deployment default. Pods are replaced a few at a time, each new one taking traffic once ready, so the split follows the Pod count and versions mix.

Blue/green: Rollback: switch back, instant. Extra: a full second copy. Mixed: never: one switch. Traffic to v2 over time: start 0%, green up 0%, tested 0%, switch 100%, done 100%. Green, v2, runs beside blue at full size and is tested without live traffic. One switch, such as a Service selector, moves all traffic; switching back is the rollback.

Canary: Rollback: send 0% to v2. Extra: a few Pods. Mixed: yes, on purpose. Traffic to v2 over time: start 0%, canary 5%, metrics OK 25%, half 50%, done 100%. v2 first gets 5% of traffic while its errors and latency are compared to v1’s. Each step goes ahead only if metrics stay healthy; a bad canary hurts few users.

Takeaway: Rolling updates replace Pods gradually and mix versions. Blue/green runs two full copies and switches all traffic at once. Canary sends a small, measured share to the new version first.

Which release strategy?If v1 and v2 cannot run at the same time, for example because of an incompatible change, use blue/green or recreate. If they can, and a bad release must reach as few users as possible, use a canary with metric checks. Otherwise the default rolling update is enough.noyesyesnoCan v1 and v2serve together?Blue/green,or RecreateLimit the blastradius of a badrelease?Canary withmetric checksRolling update,the default
Which release strategy?If v1 and v2 cannot run at the same time, for example because of an incompatible change, use blue/green or recreate. If they can, and a bad release must reach as few users as possible, use a canary with metric checks. Otherwise the default rolling update is enough.noyesyesnoCan v1 and v2serve together?Blue/green,or RecreateLimit the blastradius of a badrelease?Canary withmetric checksRolling update,the default
Which release strategy?

In code

spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1            # at most 5 Pods during the rollout (default 25%)
      maxUnavailable: 0      # never fewer than 4 ready (default 25%)
  minReadySeconds: 10        # a new Pod must stay ready 10 s before the next step
  revisionHistoryLimit: 10   # old ReplicaSets kept for rollback
A rolling update that never drops below full capacity
kubectl set image deployment/orders orders=registry.example.com/orders:1.4.3
kubectl annotate deployment/orders kubernetes.io/change-cause="1.4.3: faster checkout" --overwrite
kubectl rollout status deployment/orders          # waits; fails after progressDeadlineSeconds, 600
kubectl rollout history deployment/orders         # 1 <none>   2 1.4.3: faster checkout
kubectl rollout undo deployment/orders            # scales the previous ReplicaSet back up
kubectl rollout undo deployment/orders --to-revision=1
Roll out, watch, roll back
kubectl apply -f orders-green.yaml                # version: green, full size, no traffic yet
kubectl rollout status deployment/orders-green
kubectl patch service orders -p '{"spec":{"selector":{"app":"orders","version":"green"}}}'
# rollback: the same patch with "blue"; delete orders-blue once green has proved itself
Blue/green with plain Kubernetes: two Deployments, one Service selector
helm upgrade --install orders ./charts/orders -f values-prod.yaml --set image.tag=1.4.3
helm history orders                               # one revision per upgrade
helm rollback orders 6                            # back to revision 6

# GitOps: commit the new tag; Argo CD or Flux sees the change and applies it
git commit -am "orders 1.4.3" && git push         # rollback = git revert, pushed the same way
Helm packages the manifests; GitOps applies them from Git
# Which build is this? Nodes may pull different ones, and undo restores the same tag
 Wrong image: registry.example.com/orders:latest

# One immutable version per build: the ReplicaSet history means something
 Right image: registry.example.com/orders:1.4.3
A moving tag makes every rollout and rollback a guess
A GitOps release, and its rollbackThe pipeline builds image 1.4.3 and opens a pull request that changes the tag in the deployment repository. After review it is merged. Argo CD, running in the cluster, notices that Git and the cluster differ and applies the change, which starts a rolling update. To roll back, someone reverts the commit and Argo CD applies the previous version the same way.ClusterArgo CDGit, deploy repoCI pipelinepull request: tag 1.4.3review and mergepoll: desired state changedapply: rolling update to 1.4.3git revert, if it goes wrongapply: back to 1.4.2
A GitOps release, and its rollbackThe pipeline builds image 1.4.3 and opens a pull request that changes the tag in the deployment repository. After review it is merged. Argo CD, running in the cluster, notices that Git and the cluster differ and applies the change, which starts a rolling update. To roll back, someone reverts the commit and Argo CD applies the previous version the same way.ClusterArgo CDGit, deploy repoCI pipelinepull request: tag 1.4.3review and mergepoll: desired state changedapply: rolling update to 1.4.3git revert, if it goes wrongapply: back to 1.4.2
A GitOps release, and its rollback

Solve it

Every rolling update causes five minutes of errors

orders 1.5.0 renames the column customer to customer_id, and its Flyway migration runs at startup. During each rollout, about half the requests fail with “column customer does not exist” until the last old Pod is gone. Explain why and ship the rename without errors.

  1. See the mixed window. A rolling update runs v1 and v2 together. The first v2 Pod migrates the shared database, so every v1 Pod still serving traffic queries a column that no longer exists.
  2. Rule out the easy escape. Blue/green does not help: blue and green share the database too, and a rollback after the rename would break blue. The schema must work with both versions.
  3. Expand, then contract. Release 1: add customer_id, write both columns, read the new one with a fallback. Backfill. Release 2: stop using customer. Release 3: drop it, once no running version needs it.
  4. Keep each step reversible. Every release now works with the schema before and after it, so kubectl rollout undo is always safe. Run migrations as a Job before the rollout rather than at Pod startup.
  5. Check. During each rollout the error rate stays flat, and rolling back release 2 to release 1 also works.
@Entity
class Order {
    @Id Long id;
    @Column(name = "customer")    String legacyCustomer;   // dropped in release 3
    @Column(name = "customer_id") String customerId;       // added by V15__add_customer_id.sql

    void setCustomer(String id) {
        this.customerId = id;
        this.legacyCustomer = id;                           // v1 Pods still read this column
    }

    String customer() {
        return customerId != null ? customerId : legacyCustomer;   // rows not backfilled yet
    }
}
Release 1 of 3: write both columns, read the new one with a fallback

How to answer

  • All three need readiness probes, so traffic only reaches Pods that can serve.
  • Recreate stops all old Pods first, with downtime, for versions that must never overlap.
  • Every strategy shares the database, so schema changes must suit both versions.
  • Canary and blue/green need extra tooling, such as Argo Rollouts, Flagger or a service mesh.

Common mistakes

  • Claiming blue/green avoids database compatibility problems.
  • Calling it a canary without metrics that decide whether to continue.

Follow-up questions

A release goes wrong in production. How do you roll back on Kubernetes?

Fastest is kubectl rollout undo: the Deployment keeps old ReplicaSets, up to revisionHistoryLimit, 10 by default, and scales the previous one back up as a rolling update, with no rebuild. With Helm, helm rollback to an earlier revision. With GitOps, revert the commit, and the controller applies the old version, which keeps Git the source of truth; an undo done by hand would be overwritten at the next sync. Rollback only works if the database schema still suits the old version.

  • kubectl rollout history shows revisions; annotate change-cause to make them readable.
  • A rollout that stalls fails after progressDeadlineSeconds, 600 by default, but is not undone automatically.
  • Expand-and-contract schema changes keep every release reversible.

See it in the infographic: Rolling, blue/green and canary

What are Helm and GitOps, and how do they fit together?

Helm is a package manager for Kubernetes: a chart is a set of templated manifests, values files fill them per environment, and each install or upgrade is a numbered release you can roll back. GitOps is an operating model: the desired state of the cluster lives in Git, and an agent in the cluster, such as the continuous delivery tools Argo CD or Flux, continuously pulls it and reconciles the cluster to match. They combine well: Argo CD can render Helm charts from Git.

  • With GitOps, every change is a reviewed commit, and rollback is git revert.
  • The CI (continuous integration) pipeline needs no cluster credentials; the agent pulls instead.
  • Drift, a change made by hand, is reported or undone automatically.

See it in the infographic: Rolling, blue/green and canary

How do you make a rolling update of a Spring Boot service truly zero-downtime?

Traffic must only reach Pods that can serve and must drain from Pods that stop. Give it a readiness probe, so new Pods get traffic only once started; maxUnavailable 0 and maxSurge 1, so capacity never drops; graceful shutdown with a preStop sleep of a few seconds, so endpoints update before the app stops; and a PodDisruptionBudget for node drains. Keep APIs and database schemas backward compatible, since old and new versions serve side by side.

  • A startup probe protects a slow JVM (Java Virtual Machine) start from liveness kills.
  • minReadySeconds catches Pods that crash right after turning ready.
  • Watch the error rate during the rollout and stop it if it climbs.

See it in the infographic: Rolling, blue/green and canary

How do you run a 5% canary on plain Kubernetes?

Only roughly: a second Deployment with the same labels behind the same Service, sized as 1 Pod against 19, gives about 5%, but the split follows Pod counts and connections, not requests. Exact weights need an ingress controller or Gateway that splits by weight, a service mesh, or Argo Rollouts and Flagger, which also automate the metric checks and the promotion.

Check yourself

1. A release must switch all users at once, and roll back in seconds if anything looks wrong. You have spare capacity. Which strategy fits?
Show answers
  • Blue/green: Correct. Both versions run in full, and one switch moves traffic either way.
  • A rolling update: Incorrect. Rollback is another gradual rollout, and versions mix meanwhile.
  • A canary: Incorrect. A canary moves traffic gradually, not all at once.
2. A Deployment has 4 replicas and the default strategy, maxSurge 25% and maxUnavailable 25%. During a rolling update, what are the most Pods and the fewest ready Pods?
Show answers
  • At most 5 Pods, at least 3 ready: Correct. 25% of 4 is 1 extra Pod, and 1 may be unavailable.
  • At most 8 Pods, at least 4 ready: Incorrect. That would be blue/green, a full second copy.
  • At most 4 Pods, possibly none ready: Incorrect. That is the Recreate strategy, with downtime.