InsightsDevOps
Canary releases that roll back on their own
Using Argo Rollouts and Prometheus to send a small share of traffic to a new version, measure it, and roll back automatically when it misbehaves.
Published November 10, 20263 min read
Most deployment pipelines end at "the new version is running". Whether it is working is left to dashboards, alerts and whoever happens to be watching. A canary release closes that gap. The new version gets a small share of real traffic, the pipeline measures it, and the release continues only if the numbers hold. If they don't, it rolls back without waiting for a person.
The shape of a canary
Three things make it work:
- Gradual traffic shifting, so a bad version reaches few users.
- Automated analysis against metrics that reflect user experience.
- Automatic rollback when the analysis fails. If someone has to notice and react, rollback comes too late.
Argo Rollouts
Argo Rollouts replaces a Kubernetes Deployment with a Rollout resource that understands canary steps. The pod template is the same; the strategy is new:
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: checkout
spec:
replicas: 10
strategy:
canary:
steps:
- setWeight: 10
- pause: { duration: 5m }
- setWeight: 30
- pause: { duration: 10m }
- setWeight: 60
- pause: { duration: 10m }
analysis:
templates:
- templateName: success-rate
startingStep: 1
args:
- name: service
value: checkout
selector:
matchLabels:
app: checkout
template:
# the same pod template the Deployment hadThe analysis runs in the background from the first pause onwards. If it fails at any point, Rollouts aborts the release, sends all traffic back to the stable version and scales the canary down.
Defining "healthy"
An AnalysisTemplate turns a Prometheus query into a pass or fail result:
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: success-rate
spec:
args:
- name: service
metrics:
- name: success-rate
interval: 1m
failureLimit: 2
successCondition: result[0] >= 0.99
provider:
prometheus:
address: http://prometheus.monitoring:9090
query: |
sum(rate(http_requests_total{service="{{args.service}}", code!~"5.."}[2m]))
/
sum(rate(http_requests_total{service="{{args.service}}"}[2m]))The query runs every minute, and the result must stay at or above 99%. Two failed measurements are tolerated, to absorb noise; a third aborts the release.
Some choices matter more than the syntax:
- Measure what users feel. Use error ratio and latency at the edge, not CPU or pod restarts.
- Measure the canary, not the whole service. At 10% weight, a broken canary barely moves a service-wide ratio. Where your metrics carry pod or version labels, select only the canary's pods, or compare the canary with the stable version directly.
- Reuse the SLO. If the service has an objective, use the same indicator here. A release that burns error budget fast is exactly what a canary should catch. Alerting on error budget burn rate covers how to define it.
Precise weights need a traffic router
Without a traffic router, Rollouts approximates weights with replica counts. With 10 replicas, 10% is one pod, which works. With 3 replicas, the smallest step is 33%.
For exact percentages, and for canaries on services with few replicas, connect Rollouts to an ingress controller or service mesh it supports, such as NGINX, the AWS Load Balancer Controller or Istio. The router then splits traffic by weight, whatever the pod count.
Make rollback safe to automate
Automatic rollback only helps if rolling back is harmless:
- Database changes must be backward compatible. Expand the schema in one release and contract it in a later one, so the previous version still works against the new schema.
- Risky behavior goes behind feature flags, so it can be switched off without a deploy.
- Rollback must not need a build. It switches traffic back to pods that are still running.
What changes
Releases become boring in the best way. A bad version reaches a small share of users for a few minutes, then disappears without anyone being paged. Engineers deploy more often because each deploy carries less risk. Every release now produces a measured health result that can be reviewed afterwards.