{"componentChunkName":"component---src-templates-blog-post-js","path":"/blog/2026-12-04-canary-deployments-argo-rollouts/","result":{"data":{"site":{"siteMetadata":{"title":"M. Hassan Ahmed","author":"Hassan11196"}},"markdownRemark":{"id":"5f17c0d8-bf92-5a55-b0f5-b34c01e7fb46","excerpt":"A standard Kubernetes  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…","html":"<p>A standard Kubernetes <code class=\"language-text\">Deployment</code> has exactly one way to ship a new version. It does a <a href=\"https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#rolling-update-deployment\">rolling update</a>: 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.</p>\n<p>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.</p>\n<p>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 <a href=\"https://argo-cd.readthedocs.io/en/stable/\">ArgoCD</a>, and want a deploy to prove itself on a few percent of requests before it owns all of them. I will cover the <code class=\"language-text\">Rollout</code> 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.</p>\n<h2>What a rolling update gives you, and what it does not</h2>\n<p>It helps to be precise about what the default already does. A rolling update is governed by two knobs, <code class=\"language-text\">maxSurge</code> and <code class=\"language-text\">maxUnavailable</code>, which decide how many extra pods it may create and how many it may take down at a time. That controls the <em>speed and capacity</em> of the swap. It does nothing about <em>correctness</em>. 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.</p>\n<p>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 <a href=\"https://argo-rollouts.readthedocs.io/en/stable/\">Argo Rollouts</a> comes in.</p>\n<h2>The Rollout resource replaces the Deployment</h2>\n<p>Argo Rollouts is a controller plus a custom resource called <code class=\"language-text\">Rollout</code>. The <code class=\"language-text\">Rollout</code> looks almost exactly like a <code class=\"language-text\">Deployment</code>: same pod template, same replica count, same selector. What it adds is a <code class=\"language-text\">strategy</code> block that can be <code class=\"language-text\">canary</code> or <code class=\"language-text\">blueGreen</code>. Here is a canary <code class=\"language-text\">Rollout</code> with its first few steps:</p>\n<div class=\"gatsby-highlight\" data-language=\"yaml\"><pre class=\"language-yaml\"><code class=\"language-yaml\"><span class=\"token key atrule\">apiVersion</span><span class=\"token punctuation\">:</span> argoproj.io/v1alpha1\n<span class=\"token key atrule\">kind</span><span class=\"token punctuation\">:</span> Rollout\n<span class=\"token key atrule\">metadata</span><span class=\"token punctuation\">:</span>\n  <span class=\"token key atrule\">name</span><span class=\"token punctuation\">:</span> workflow<span class=\"token punctuation\">-</span>console\n<span class=\"token key atrule\">spec</span><span class=\"token punctuation\">:</span>\n  <span class=\"token key atrule\">replicas</span><span class=\"token punctuation\">:</span> <span class=\"token number\">10</span>\n  <span class=\"token key atrule\">selector</span><span class=\"token punctuation\">:</span>\n    <span class=\"token key atrule\">matchLabels</span><span class=\"token punctuation\">:</span>\n      <span class=\"token key atrule\">app</span><span class=\"token punctuation\">:</span> workflow<span class=\"token punctuation\">-</span>console\n  <span class=\"token key atrule\">template</span><span class=\"token punctuation\">:</span>\n    <span class=\"token key atrule\">metadata</span><span class=\"token punctuation\">:</span>\n      <span class=\"token key atrule\">labels</span><span class=\"token punctuation\">:</span>\n        <span class=\"token key atrule\">app</span><span class=\"token punctuation\">:</span> workflow<span class=\"token punctuation\">-</span>console\n    <span class=\"token key atrule\">spec</span><span class=\"token punctuation\">:</span>\n      <span class=\"token key atrule\">containers</span><span class=\"token punctuation\">:</span>\n        <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">name</span><span class=\"token punctuation\">:</span> console\n          <span class=\"token key atrule\">image</span><span class=\"token punctuation\">:</span> registry.internal/workflow<span class=\"token punctuation\">-</span>console<span class=\"token punctuation\">:</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">{</span> .Values.tag <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span>\n  <span class=\"token key atrule\">strategy</span><span class=\"token punctuation\">:</span>\n    <span class=\"token key atrule\">canary</span><span class=\"token punctuation\">:</span>\n      <span class=\"token key atrule\">steps</span><span class=\"token punctuation\">:</span>\n        <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">setWeight</span><span class=\"token punctuation\">:</span> <span class=\"token number\">20</span>\n        <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">pause</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token key atrule\">duration</span><span class=\"token punctuation\">:</span> 5m <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">setWeight</span><span class=\"token punctuation\">:</span> <span class=\"token number\">50</span>\n        <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">pause</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token key atrule\">duration</span><span class=\"token punctuation\">:</span> 5m <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">setWeight</span><span class=\"token punctuation\">:</span> <span class=\"token number\">100</span></code></pre></div>\n<p>If rewriting your <code class=\"language-text\">Deployment</code> as a <code class=\"language-text\">Rollout</code> feels like a big commitment, you do not have to. A <code class=\"language-text\">Rollout</code> can reference an existing <code class=\"language-text\">Deployment</code> through <a href=\"https://argo-rollouts.readthedocs.io/en/stable/migrating/#reference-deployment-from-rollout\"><code class=\"language-text\">workloadRef</code></a>, 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.</p>\n<h2>Canary steps: setWeight and pause</h2>\n<p>The whole canary strategy is a list of <code class=\"language-text\">steps</code> that run top to bottom. There are a few kinds, and you will use three of them constantly:</p>\n<ul>\n<li><code class=\"language-text\">setWeight: N</code> sends <code class=\"language-text\">N</code> percent of traffic to the new version.</li>\n<li><code class=\"language-text\">pause: { duration: 5m }</code> waits a fixed time, then continues on its own. Units are <code class=\"language-text\">s</code>, <code class=\"language-text\">m</code>, and <code class=\"language-text\">h</code>.</li>\n<li><code class=\"language-text\">pause: {}</code> with no duration stops and waits for a human to promote it. This is the manual gate.</li>\n</ul>\n<p>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 <code class=\"language-text\">kubectl argo rollouts</code> <a href=\"https://argo-rollouts.readthedocs.io/en/stable/features/kubectl-plugin/\">plugin</a>: <code class=\"language-text\">kubectl argo rollouts get rollout workflow-console --watch</code> shows the live step, and <code class=\"language-text\">promote</code> and <code class=\"language-text\">abort</code> move it forward or pull it back. An <code class=\"language-text\">abort</code> scales the canary to zero and leaves the stable version serving everything, which is your manual rollback.</p>\n<p><img src=\"/b5de43169c75e1cb17a35e8d4bca190f/canary-steps.svg\" alt=\"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.\"></p>\n<h2>The weight gotcha: replicas, not magic</h2>\n<p>Here is the detail that surprises people, and it is worth getting right before you trust a canary in production. <code class=\"language-text\">setWeight: 20</code> does not, by itself, route exactly 20% of requests to the canary. Out of the box, Argo Rollouts approximates the weight using the <em>ratio of canary pods to stable pods</em>. The <a href=\"https://argo-rollouts.readthedocs.io/en/stable/features/specification/\">specification</a> is blunt about it: without a traffic provider it will “achieve traffic split via a weighted replica count between the canary and stable ReplicaSet.”</p>\n<p>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 <code class=\"language-text\">setWeight: 5</code> 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.</p>\n<p>The fix is <code class=\"language-text\">trafficRouting</code>. 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 <a href=\"https://argo-rollouts.readthedocs.io/en/stable/features/traffic-management/\">Istio, NGINX, the AWS ALB, and SMI</a>. With a router in place, <code class=\"language-text\">setWeight: 5</code> 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.</p>\n<h2>Make the rollout decide for itself</h2>\n<p>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 <code class=\"language-text\">analysis</code>. An <a href=\"https://argo-rollouts.readthedocs.io/en/stable/features/analysis/\"><code class=\"language-text\">AnalysisTemplate</code></a> 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:</p>\n<div class=\"gatsby-highlight\" data-language=\"yaml\"><pre class=\"language-yaml\"><code class=\"language-yaml\"><span class=\"token key atrule\">apiVersion</span><span class=\"token punctuation\">:</span> argoproj.io/v1alpha1\n<span class=\"token key atrule\">kind</span><span class=\"token punctuation\">:</span> AnalysisTemplate\n<span class=\"token key atrule\">metadata</span><span class=\"token punctuation\">:</span>\n  <span class=\"token key atrule\">name</span><span class=\"token punctuation\">:</span> error<span class=\"token punctuation\">-</span>rate\n<span class=\"token key atrule\">spec</span><span class=\"token punctuation\">:</span>\n  <span class=\"token key atrule\">args</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">name</span><span class=\"token punctuation\">:</span> service<span class=\"token punctuation\">-</span>name\n  <span class=\"token key atrule\">metrics</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">name</span><span class=\"token punctuation\">:</span> error<span class=\"token punctuation\">-</span>rate\n      <span class=\"token key atrule\">interval</span><span class=\"token punctuation\">:</span> 1m\n      <span class=\"token key atrule\">count</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span>\n      <span class=\"token key atrule\">failureLimit</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span>\n      <span class=\"token key atrule\">successCondition</span><span class=\"token punctuation\">:</span> result<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> &lt; 0.01\n      <span class=\"token key atrule\">provider</span><span class=\"token punctuation\">:</span>\n        <span class=\"token key atrule\">prometheus</span><span class=\"token punctuation\">:</span>\n          <span class=\"token key atrule\">address</span><span class=\"token punctuation\">:</span> http<span class=\"token punctuation\">:</span>//prometheus.monitoring<span class=\"token punctuation\">:</span><span class=\"token number\">9090</span>\n          <span class=\"token key atrule\">query</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">|</span><span class=\"token scalar string\">\n            sum(rate(http_requests_total{service=\"{{args.service-name}}\",code=~\"5..\"}[2m]))\n            /\n            sum(rate(http_requests_total{service=\"{{args.service-name}}\"}[2m]))</span></code></pre></div>\n<p>Then you drop an analysis step into the canary sequence, right after the first weight increase:</p>\n<div class=\"gatsby-highlight\" data-language=\"yaml\"><pre class=\"language-yaml\"><code class=\"language-yaml\"><span class=\"token key atrule\">strategy</span><span class=\"token punctuation\">:</span>\n  <span class=\"token key atrule\">canary</span><span class=\"token punctuation\">:</span>\n    <span class=\"token key atrule\">steps</span><span class=\"token punctuation\">:</span>\n      <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">setWeight</span><span class=\"token punctuation\">:</span> <span class=\"token number\">20</span>\n      <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">pause</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token key atrule\">duration</span><span class=\"token punctuation\">:</span> 2m <span class=\"token punctuation\">}</span>\n      <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">analysis</span><span class=\"token punctuation\">:</span>\n          <span class=\"token key atrule\">templates</span><span class=\"token punctuation\">:</span>\n            <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">templateName</span><span class=\"token punctuation\">:</span> error<span class=\"token punctuation\">-</span>rate\n          <span class=\"token key atrule\">args</span><span class=\"token punctuation\">:</span>\n            <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">name</span><span class=\"token punctuation\">:</span> service<span class=\"token punctuation\">-</span>name\n              <span class=\"token key atrule\">value</span><span class=\"token punctuation\">:</span> workflow<span class=\"token punctuation\">-</span>console.cms<span class=\"token punctuation\">-</span>ops.svc.cluster.local\n      <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">setWeight</span><span class=\"token punctuation\">:</span> <span class=\"token number\">50</span>\n      <span class=\"token punctuation\">-</span> <span class=\"token key atrule\">setWeight</span><span class=\"token punctuation\">:</span> <span class=\"token number\">100</span></code></pre></div>\n<p>The pieces matter. <code class=\"language-text\">interval</code> and <code class=\"language-text\">count</code> mean “take five measurements, one a minute.” <code class=\"language-text\">failureLimit: 2</code> tolerates a couple of bad readings before giving up, which keeps a single scrape blip from aborting a good deploy. <code class=\"language-text\">successCondition</code> is the actual bar: 5xx rate under one percent.</p>\n<p>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 <code class=\"language-text\">Degraded</code>. That is an automatic rollback, triggered by your own metric, with nobody watching. There is also a <code class=\"language-text\">backgroundAnalysis</code> 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 <em>inconclusive</em> 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.</p>\n<h2>Where it breaks</h2>\n<p><strong>Two versions run at the same time, by design.</strong> 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 <a href=\"/blog/2026-07-03-argocd-sync-waves-ordering-rollout/\">sync waves and hooks</a>; a canary makes the “both versions coexist” requirement non-negotiable rather than merely a good idea.</p>\n<p><strong>The analysis is only as honest as the metric.</strong> A <code class=\"language-text\">successCondition</code> 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.</p>\n<p><strong>A short soak proves nothing.</strong> 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.</p>\n<p><strong>A manual gate someone forgets.</strong> A <code class=\"language-text\">pause: {}</code> 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.</p>\n<p><strong>Rollback is not instant without a router.</strong> 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.</p>\n<h2>What I would do differently</h2>\n<p>The mistake I would warn my earlier self about is reaching for <code class=\"language-text\">analysis</code> on day one. It is the most impressive feature and the easiest to get subtly wrong, because a bad <code class=\"language-text\">successCondition</code> fails in the direction you least want: silently passing bad deploys. Start simpler. Run a canary with time-based pauses and a manual <code class=\"language-text\">promote</code>, and watch your existing dashboards by hand for a week of real deploys. That tells you which metric actually moves when something is wrong. <em>Then</em> encode that metric as an <code class=\"language-text\">AnalysisTemplate</code>, because now you are automating a judgment you have already made correctly by hand, instead of guessing at a threshold.</p>\n<p>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.</p>\n<h2>Where this runs</h2>\n<p>Moving the <a href=\"/project/cms-workflow-operations/\">CMS workflow management services</a> 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 <a href=\"/blog/2026-07-01-opensearch-workflow-monitoring/\">OpenSearch dashboards for workflow monitoring</a>. GitOps makes the cluster match Git. Argo Rollouts decides how carefully the new version is allowed to take over once it gets there.</p>\n<p><em>Diagram by M. Hassan Ahmed, made for this post.</em></p>","frontmatter":{"title":"Canary Deploys on Kubernetes with Argo Rollouts","date":"2026-12-04T00:00:00.000Z","description":"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.","thumbnail":{"childImageSharp":{"fluid":{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAIAAADwazoUAAAACXBIWXMAAAsSAAALEgHS3X78AAAB2ElEQVQozz3QW3OaQBTAcR5TjRf2ziJREMRwRxSDRq2SKOahmVwe2pk27ff/FD1Qm5nfnNlhzn92FqWNzA62OmR8TcYdanep02Vg0uVuYwp6/LYngNfT/H4t6EsQKtfEaiHzqj9sqTBHV6rZwlYLj78gmHYLjesYskt5yfp6pOqR0saWHKWuvxk5Sy/eT4Od6RZOuJ2mpZvsveyRD2dQ1oEMVR1AFquDBA0Spa1aelT41bO9O4bVc/D0MimfzHg7ifZWsHWTAzez+k4Z/c8uJTJSpUNsZMXUz2mYY29OgpxFBRolqgyxAUtxV/j1nfLzzvhfiYyZAk9SxS1iPsIeJgHmIZYxHqR0mAEyzGAPN6voJsNgOP/UxJqPnTnNdmS2wdOCDBbEWNBaTs0lHa8YsGvUXjN7DV+Es6JmrvQ0T2U+X+3kr1f64xs+Hml0T5INwDAh1hd0kNeMJQM3d3DQ3DWzlgr8eiRCvvo6+HjXv7/In6/izzv//UY/3ijM8sSWB1Y8ANpgq0eal9LfCmfdxDLm6UY/nbXyVDs0ykrsj+xYsepMG+TUqM74odK8jXDuIQ6RkRA9RTzCPMYiAURLqZzBAbEYsQSzhPCUiBkRGdXmVC7I6I6axV+XEl8PjQlA/QAAAABJRU5ErkJggg==","aspectRatio":1.899441340782123,"src":"/static/f1f62a324586966de53304a93818acc6/40a76/hero.png","srcSet":"/static/f1f62a324586966de53304a93818acc6/c972b/hero.png 340w,\n/static/f1f62a324586966de53304a93818acc6/27625/hero.png 680w,\n/static/f1f62a324586966de53304a93818acc6/40a76/hero.png 1360w,\n/static/f1f62a324586966de53304a93818acc6/ed396/hero.png 2000w","sizes":"(max-width: 1360px) 100vw, 1360px"}}}}}},"pageContext":{"slug":"/2026-12-04-canary-deployments-argo-rollouts/","previous":"blog/2026-11-26-virtualize-long-chat-transcript-react/","next":null}},"staticQueryHashes":["32046230"]}