Skip to main content

Canary Deployment

A canary deployment is a release strategy that sends a small share of real traffic, often 5 to 10 percent, to the new version while the rest stays on the stable one. If metrics stay healthy, the share grows until the canary becomes the full release.

What a canary protects you from

Staging rarely reproduces production traffic, data shapes, or concurrency. A canary exposes the new version to a controlled slice of real users, so a bug reaches few people and rollback is just removing the canary. The name comes from canaries once carried into mines to detect gas early.

Two ways to split traffic

Method Precision Needs
Replica ratio Approximate Plain Deployments and one Service
Weighted routing Exact Service mesh, ingress, or Argo Rollouts and Flagger

With replica ratios, 1 canary pod behind 9 stable pods gets roughly 10 percent of new connections. kube-proxy balances per connection, so long-lived connections skew the split.

flowchart TD I["Incoming traffic"] -->|"weights"| W{"Traffic split"} W -->|"95 percent"| S["Stable v1.9.0"] W -->|"5 percent"| C["Canary v2.0.0"] C -->|"metrics healthy"| P["Promote gradually"] C -->|"errors rise"| R["Roll back to 0"] classDef start fill:#475569,color:#ffffff classDef stable fill:#D1FAE5,color:#1E293B classDef canary fill:#FFEDD5,color:#1E293B classDef bad fill:#FEE2E2,color:#1E293B class I,W start class S,P stable class C canary class R bad

Replica-based canary

Bash
# Stable: 9 replicas (track=stable). Canary: 1 replica (track=canary).
# The Service selects only app=notification-api, so it covers both.
kubectl scale deployment notification-api-canary --replicas=3 -n production
kubectl scale deployment notification-api-stable --replicas=7 -n production
# Emergency rollback
kubectl scale deployment notification-api-canary --replicas=0 -n production
kubectl scale deployment notification-api-stable --replicas=10 -n production

Signals to compare per version

  • 5xx error rate on canary vs stable
  • p99 latency on canary vs stable
  • Container restarts and OOMKills
  • Memory growth over time, to catch leaks
TEXT
sum by (track) (rate(http_requests_total{status=~"5..", namespace="production"}[5m]))
/ sum by (track) (rate(http_requests_total{namespace="production"}[5m]))
Remember

Hold each step long enough to see a trend. A leak that looks fine at 10 percent for five minutes may only show at 30 percent after 20 minutes.

Tip

Automate promotion and rollback with Argo Rollouts or Flagger so a bad canary at 2am is reverted without a human in the loop.

Common Mistake

Trusting error rates from too little traffic. If the canary receives a handful of requests per minute, the numbers are statistically meaningless.

Frequently Asked Questions

What does a canary catch that staging does not?

Real traffic patterns, real data edge cases, and real downstream interactions. Memory leaks under actual concurrency and unusual user input are typical examples.

What do I need beyond a normal Deployment to run a precise canary?

Weighted traffic splitting, from a service mesh such as Istio, an ingress controller with canary support, or a progressive delivery tool such as Argo Rollouts or Flagger. Replica ratios only approximate the percentage.

How is canary different from blue-green?

A canary shifts traffic gradually and needs little extra capacity, while blue-green flips everything at once and needs a full second environment. Canary gives gradual confidence, blue-green gives instant rollback.

Found a mistake, an outdated step or a broken link?