Canary Deploys on Kubernetes with Argo Rollouts

A rolling update pushes a bad version to everyone at once. Argo Rollouts shifts traffic to a canary in steps, checks the metrics, and rolls back for you.

A standard Kubernetes Deployment has exactly one way to ship a new version. It does a rolling update: scale up the new ReplicaSet a few pods at a time, scale down the old one to match, and keep going until every pod is the new version. It is fast and it is hands-off, and most days that is all you want.

The problem shows up on the day the new version has a bug that only appears under real traffic. A query that was fine in staging turns out to be slow against the production dataset. A serialization change breaks one client you forgot about. The pods all pass their readiness probe, because the bug is not a crash, so the rolling update sails right through. By the time a dashboard turns red, every pod is the new version and every user is hitting it. Rolling back is another full rolling update, and the minutes in between are the incident.

A canary deployment shrinks that blast radius. You give the new version a small slice of traffic, watch how it behaves, and only widen the slice once it has earned it. This post is for people who already run services on Kubernetes, probably through ArgoCD, and want a deploy to prove itself on a few percent of requests before it owns all of them. I will cover the Rollout resource that makes this work, how the canary steps are defined, the one thing about traffic weight that catches everyone, and how to make the rollout roll itself back when the metrics go bad.

What a rolling update gives you, and what it does not

It helps to be precise about what the default already does. A rolling update is governed by two knobs, maxSurge and maxUnavailable, which decide how many extra pods it may create and how many it may take down at a time. That controls the speed and capacity of the swap. It does nothing about correctness. The new pods take production traffic the instant they pass readiness, and readiness is a liveness signal, not a “this version is actually good” signal. There is no pause, no measurement, no gate. The only decision the Deployment makes is whether a pod is up.

A canary adds the decision that is missing: hold here, look at how the new version is doing, and decide whether to continue. Kubernetes has no native object for that, which is where Argo Rollouts comes in.

The Rollout resource replaces the Deployment

Argo Rollouts is a controller plus a custom resource called Rollout. The Rollout looks almost exactly like a Deployment: same pod template, same replica count, same selector. What it adds is a strategy block that can be canary or blueGreen. Here is a canary Rollout with its first few steps:

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: workflow-console
spec:
  replicas: 10
  selector:
    matchLabels:
      app: workflow-console
  template:
    metadata:
      labels:
        app: workflow-console
    spec:
      containers:
        - name: console
          image: registry.internal/workflow-console:{{ .Values.tag }}
  strategy:
    canary:
      steps:
        - setWeight: 20
        - pause: { duration: 5m }
        - setWeight: 50
        - pause: { duration: 5m }
        - setWeight: 100

If rewriting your Deployment as a Rollout feels like a big commitment, you do not have to. A Rollout can reference an existing Deployment through workloadRef, and Argo will take over managing its pods without you copying the pod spec into a new file. That makes adoption a small, reversible change rather than a rewrite.

Canary steps: setWeight and pause

The whole canary strategy is a list of steps that run top to bottom. There are a few kinds, and you will use three of them constantly:

  • setWeight: N sends N percent of traffic to the new version.
  • pause: { duration: 5m } waits a fixed time, then continues on its own. Units are s, m, and h.
  • pause: {} with no duration stops and waits for a human to promote it. This is the manual gate.

The rollout in the example above goes to 20% of traffic, soaks for five minutes, goes to 50%, soaks again, then takes the rest. At any point you can watch and steer it with the kubectl argo rollouts plugin: kubectl argo rollouts get rollout workflow-console --watch shows the live step, and promote and abort move it forward or pull it back. An abort scales the canary to zero and leaves the stable version serving everything, which is your manual rollback.

A canary rollout drawn as a sequence of steps: setWeight 20, pause, an analysis gate, setWeight 50, then promotion to 100%. A dashed red branch shows a failed analysis aborting the rollout and dropping canary weight to zero. Below, four traffic bars show the user-facing split at each stage, from all-stable to all-new.

The weight gotcha: replicas, not magic

Here is the detail that surprises people, and it is worth getting right before you trust a canary in production. setWeight: 20 does not, by itself, route exactly 20% of requests to the canary. Out of the box, Argo Rollouts approximates the weight using the ratio of canary pods to stable pods. The specification is blunt about it: without a traffic provider it will “achieve traffic split via a weighted replica count between the canary and stable ReplicaSet.”

That has a consequence you can work out on a napkin. If you run five replicas, the smallest slice you can express is one pod, which is 20%. Ask for setWeight: 5 on five replicas and you cannot get there; the canary still gets a full fifth of the traffic. To run a genuine 5% canary you need at least twenty pods. For a lot of internal services that replica count is fine. For a small service it means your “5% canary” is a fiction, and the first time you notice is when a bad version takes a bigger bite than you planned.

The fix is trafficRouting. When you wire the Rollout to an ingress controller or service mesh, Argo asks that layer to split traffic by real percentages, independent of pod counts. Supported providers include Istio, NGINX, the AWS ALB, and SMI. With a router in place, setWeight: 5 means five percent, and you can run a tiny canary on a handful of pods. The tradeoff is that you have taken on a dependency: the canary is now only as reliable as the mesh or ingress doing the splitting, and that is one more component to understand when something misroutes.

Make the rollout decide for itself

Time-based pauses are a good start, but they still rely on a human looking at a graph during the soak. The step that removes the human is analysis. An AnalysisTemplate queries a metrics source during the rollout and lets the result drive the decision. A common one checks the canary’s error rate against Prometheus:

apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
  name: error-rate
spec:
  args:
    - name: service-name
  metrics:
    - name: error-rate
      interval: 1m
      count: 5
      failureLimit: 2
      successCondition: result[0] < 0.01
      provider:
        prometheus:
          address: http://prometheus.monitoring:9090
          query: |
            sum(rate(http_requests_total{service="{{args.service-name}}",code=~"5.."}[2m]))
            /
            sum(rate(http_requests_total{service="{{args.service-name}}"}[2m]))

Then you drop an analysis step into the canary sequence, right after the first weight increase:

strategy:
  canary:
    steps:
      - setWeight: 20
      - pause: { duration: 2m }
      - analysis:
          templates:
            - templateName: error-rate
          args:
            - name: service-name
              value: workflow-console.cms-ops.svc.cluster.local
      - setWeight: 50
      - setWeight: 100

The pieces matter. interval and count mean “take five measurements, one a minute.” failureLimit: 2 tolerates a couple of bad readings before giving up, which keeps a single scrape blip from aborting a good deploy. successCondition is the actual bar: 5xx rate under one percent.

What happens on failure is the point of the whole exercise. When an analysis run fails, Argo aborts the rollout, sets the canary weight back to zero, and marks the Rollout Degraded. That is an automatic rollback, triggered by your own metric, with nobody watching. There is also a backgroundAnalysis variant that runs continuously alongside the steps rather than as a blocking gate, so a regression that only appears at 50% traffic still trips the same wire. One thing to know: an inconclusive result (neither success nor failure condition matched) does not roll back; it pauses the rollout where it stands and waits for you. So a Prometheus that goes missing mid-rollout stalls the deploy rather than failing it, which is usually the safer default but worth knowing when a rollout seems stuck for no reason.

Where it breaks

Two versions run at the same time, by design. The entire point of a canary is that the old and new code serve traffic together for a while. That is fine for stateless request handling and a trap for anything that shares a database schema. If the new version needs a column the old version cannot tolerate, the canary window is exactly when both are live against the same table. The schema has to be compatible with both versions at once, which is the same expand-then-contract discipline you need for ordered migrations. I wrote about getting that ordering right under ArgoCD in sync waves and hooks; a canary makes the “both versions coexist” requirement non-negotiable rather than merely a good idea.

The analysis is only as honest as the metric. A successCondition on a query that barely moves under real load will pass every bad deploy. Worse is a metric that lies during warmup: a fresh pod with a cold cache or an empty connection pool looks slow for the first minute, and if your analysis starts measuring immediately it can abort a perfectly good version. Give the canary a short pause to warm up before the first measurement, and pick a metric that actually reacts to the failures you care about.

A short soak proves nothing. Some bugs are a function of time, not traffic: a slow memory leak, a cache that fills, a cron that fires on the hour. A ninety-second canary never sees them. The soak has to be long enough for the failure mode you are worried about to show up, which means there is no single right duration, only a duration matched to the risk.

A manual gate someone forgets. A pause: {} with no duration will sit there forever. That is the feature, but it also means a rollout can quietly sit half-promoted at 20% for a day because the person who was supposed to promote it went to lunch. If you use manual gates, you need something that tells you a rollout is waiting, or they turn into stuck deploys.

Rollback is not instant without a router. When you abort a replica-count canary, the stable ReplicaSet still has to scale back up to full capacity if it was scaled down. That is seconds to a minute, not zero. With a traffic router the shift back is immediate because it is just a weight change. If a fast rollback matters to you, that is another reason to run the router.

What I would do differently

The mistake I would warn my earlier self about is reaching for analysis on day one. It is the most impressive feature and the easiest to get subtly wrong, because a bad successCondition fails in the direction you least want: silently passing bad deploys. Start simpler. Run a canary with time-based pauses and a manual promote, and watch your existing dashboards by hand for a week of real deploys. That tells you which metric actually moves when something is wrong. Then encode that metric as an AnalysisTemplate, because now you are automating a judgment you have already made correctly by hand, instead of guessing at a threshold.

The other thing: do not over-step the rollout. A canary with eight weight increases and a pause between each one is not safer than one with three, it is just slower, and every extra step is another place a deploy can stall. Twenty, fifty, a hundred, with one good analysis gate near the start, covers most of the risk.

Where this runs

Moving the CMS workflow management services onto Kubernetes and ArgoCD is what made safe updates and quick rollbacks possible at all; it is specifically called out in the work that earned the 2024 CMS Award. A rolling update gets you the quick rollback. A canary is the next step: it means a bad version is caught on a slice of traffic instead of all of it, and with analysis in place it is caught by a metric rather than by whoever happens to be looking. The health signal your analysis reads is the same one worth watching over time, which is the kind of view I described building in OpenSearch dashboards for workflow monitoring. GitOps makes the cluster match Git. Argo Rollouts decides how carefully the new version is allowed to take over once it gets there.

Diagram by M. Hassan Ahmed, made for this post.