Lesson 06 of 16 · Releasing safely
Canary analysis with Argo Rollouts
Make each cell's release check itself: convert a Deployment to an Argo Rollouts canary, send a small share of traffic to the new version, run an analysis that compares it with the stable version, and abort automatically when it misbehaves, even when readiness probes still pass. Tested end to end, with a deterministic bad release.
Probes are not enough
A readiness probe tells Kubernetes a pod can accept traffic. It does not tell you whether the new version is correct: a release can pass every probe and still return errors on real requests. Canary analysis closes that gap by watching how the new version actually behaves on a small share of traffic, and aborting automatically if it is worse.
Before changing the recipe for the whole school, the cook gives the new version to one table and watches their faces. If anyone looks ill, everyone else keeps the old recipe.
From Deployment to Rollout
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: tenant-api
spec:
replicas: 4
selector:
matchLabels: { app.kubernetes.io/name: tenant-api }
template:
metadata:
labels: { app.kubernetes.io/name: tenant-api }
spec:
containers:
- name: app
image: ghcr.io/stefanprodan/podinfo:6.7.1
ports: [ { name: http, containerPort: 9898 } ]
readinessProbe: { httpGet: { path: /readyz, port: http } }
livenessProbe: { httpGet: { path: /healthz, port: http } }
strategy:
canary:
stableService: tenant-api # Rollouts points this Service at the stable pods
canaryService: tenant-api-canary # …and this one at the canary pods only
steps:
- setWeight: 25
- analysis:
templates: [ { templateName: canary-health } ]
args: [ { name: canary-service, value: tenant-api-canary } ]
- pause: { duration: 20s }
- setWeight: 50
- pause: { duration: 20s }
Two Services, one per version, let the analysis target only canary pods. Without a traffic router, weights are approximated by replica counts; with a mesh or Gateway API plugin, Rollouts sets exact weights and can route by header (for example only internal testers, or only one tenant's requests) before any percentage.
The analysis
The tested template calls the canary Service and requires every response to be valid:
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: canary-health
spec:
args:
- name: canary-service
metrics:
- name: canary-http-ok
interval: 3s
count: 10
failureLimit: 0
successCondition: result.version != ""
provider:
web:
url: "http://{{ args.canary-service }}.tenant-api.svc/"
timeoutSeconds: 5
jsonPath: "{$}"
In production, compare canary with stable using Prometheus, rather than an absolute threshold:
provider: prometheus, query (error ratio of the canary minus that of the stable version):
sum(rate(http_requests_total{service="tenant-api-canary",code=~"5.."}[2m]))
/ sum(rate(http_requests_total{service="tenant-api-canary"}[2m]))
- sum(rate(http_requests_total{service="tenant-api",code=~"5.."}[2m]))
/ sum(rate(http_requests_total{service="tenant-api"}[2m]))
successCondition: result[0] < 0.01 (no more than 1 point worse)
Add a latency metric (p99 of the canary not more than, say, 20% above stable) and, where available, a business signal (logins succeeding, orders completing).
A deterministic bad release
To test the safety net, make the new version fail on real requests while its probes stay green. With podinfo, the --random-error flag does exactly that:
command: [ "./podinfo", "--port=9898", "--random-error=true" ]
Push it and watch: weight goes to 25%, the AnalysisRun sees HTTP 500s and fails, the Rollout aborts, traffic returns to stable, the canary scales to zero, and Argo CD shows the app as Degraded. Recover with git revert. Retrying would just run the same bad revision again.
Found while testing
podinfo also documents an environment variable for random errors, but in version 6.7.1 only the command-line flag had any effect. When you build a failure test, verify that it really fails.
Rollouts and rings together
- Rings protect the fleet: a change reaches more cells only after earlier rings are healthy.
- Canaries protect each cell: a bad version is stopped within one analysis interval, before most of the cell's traffic sees it.
- Promotion between rings can also require a successful analysis, not just Healthy status.
Try it
Install Argo Rollouts on a cluster (an ApplicationSet add-on, Helm chart argo-rollouts), deploy the Rollout, both Services and the AnalysisTemplate through Git. Release a harmless change (an environment variable) and watch the steps. Then release the --random-error version and watch the abort. Revert in Git.
Recap
- Probes check readiness; canary analysis checks correctness on real traffic.
- A Rollout with stable and canary Services, weights, analysis steps and pauses aborts bad releases automatically.
- Compare canary with stable (errors, latency, business signals); recover with
git revert. - Rings protect the fleet; canaries protect each cell.
This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.