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.
Replica-based canary
# 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 productionkubectl scale deployment notification-api-stable --replicas=7 -n production # Emergency rollbackkubectl scale deployment notification-api-canary --replicas=0 -n productionkubectl scale deployment notification-api-stable --replicas=10 -n productionSignals 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
sum by (track) (rate(http_requests_total{status=~"5..", namespace="production"}[5m])) / sum by (track) (rate(http_requests_total{namespace="production"}[5m]))RememberHold 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.
TipAutomate promotion and rollback with Argo Rollouts or Flagger so a bad canary at 2am is reverted without a human in the loop.
Common MistakeTrusting 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.