Workflow: Traffic, Metrics, a Threshold
What a Canary Needs
Three things, and a fourth so that someone knows:
- Traffic through the split - requests that pass the place where the new and the old version share the load. Without them the canary measures nothing.
- Metrics of the canary’s own requests - not the service’s average: the canary’s success rate and latency, separately.
- A threshold - what counts as healthy, and how many failed checks end the release.
- An alert when it rolls back - a rejected release is a failure of the release process, and it must reach a person.
The story had a threshold and nothing else.
A Release, Step by Step
The Canary names the frontend’s Deployment. From then on, Flagger owns how a new version of it reaches users:
The frontend canary
Show canary-frontend.yaml
# Chapter 19: every new frontend release in develop goes to a share of the traffic first. Flagger
# watches the frontend Deployment; a change to its pod template (a new image, a new env) starts an
# analysis: the new version runs as the canary, Traefik sends it 10%, then 20% ... 50% of the
# requests while the success rate and the latency of the canary's own requests are checked every
# 30 s. Three failed checks and the canary gets 0% again and the release is rolled back; all checks
# passed and the new version becomes the primary - the Deployment that serves everyone.
#
# Only the frontend: static files and a proxy, no data - going back is the previous image and
# nothing else. A service that owns data needs its schema to fit both versions first (Chapter 18).
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
name: frontend
namespace: develop
spec:
provider: traefik
targetRef:
apiVersion: apps/v1
kind: Deployment
name: frontend
# Flagger copies this HPA to frontend-primary (the serving Deployment) and leaves the canary
# Deployment at 0 between releases (an HPA does not scale a Deployment that is at 0 replicas).
autoscalerRef:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
name: frontend
progressDeadlineSeconds: 600
# Deleting the Canary (disabling the module) restores the app: Flagger scales the Deployment back
# up and points the Service at it again. Without it the Service keeps selecting the deleted
# primary and the Deployment may stay at 0 replicas (an HPA does not scale up from 0).
revertOnDeletion: true
service:
port: 8080
targetPort: http
analysis:
interval: 30s
threshold: 3 # failed checks before the rollback
stepWeight: 10 # 10% more traffic per passed check ...
maxWeight: 50 # ... up to half; then the canary is promoted
metrics:
# Flagger's built-in Traefik queries over the canary's own requests (traefik_service_*):
# the share of non-5xx answers, and the 99th percentile latency in milliseconds. A check with
# no requests to measure fails - synthetic-traffic.yaml keeps requests coming.
- name: request-success-rate
thresholdRange:
min: 99
interval: 1m
- name: request-duration
thresholdRange:
max: 500
interval: 1m
- When enabled, Flagger copies the Deployment
frontendtofrontend-primary- the version that serves - with its own copy of the HPA, points the Servicefrontendat it, and scalesfrontendto 0. Between releases,frontendis only a template. - A release changes
frontend- a new image from Git, a new environment variable, anything in the pod template. Flux applies it as always; Flagger sees the change and scalesfrontendup: that is the canary. - Traffic shifts in steps. Flagger writes a TraefikService with two weighted entries, primary and canary, and every 30 seconds checks the canary’s success rate (at least 99% non-5xx) and its 99th-percentile latency (at most 500 ms) over the last minute. A passed check adds 10%, up to 50%.
- Promotion: after the check at 50%, Flagger copies the canary’s pod template into
frontend-primary, waits for its rollout, gives it all the traffic and scales the canary back to 0. - Rollback: three failed checks - the canary gets 0%, is scaled to 0, and the Canary turns
Failed.frontend-primarynever changed: the requests it served saw nothing of the bad release.
On kind the whole way takes about four and a half minutes for a healthy release; a release that failed three requests in ten was rolled back at 20% of the traffic after about two and a half.
The Route: Why an IngressRoute Next to the Ingress
Users reach the frontend through Traefik, so Traefik is where the split happens. The split is a TraefikService - and a Kubernetes Ingress cannot point at one: Traefik answers Resource backends are not supported (found on kind). So the canary module adds an IngressRoute for develop.safeops.work to the TraefikService.
The overlay’s Ingress stays. On the cloud cluster, external-dns creates the DNS record from it and removes records whose Ingress is gone (policy: sync); cert-manager issues the TLS certificate from its annotations. Both routes match the same host; the IngressRoute wins by an explicit priority: 1000 - Traefik’s default priority is the length of the rule, and the Ingress’s rule is the longer one. Switching the module off removes the IngressRoute, and the Ingress serves again.
A route is a public door, whatever it was made for. The routes of the story matched an internal name on the public entrypoint: anyone could have sent that Host header to the load balancer.
The Data: Metrics and Requests
- Traefik’s metrics. A PodMonitor scrapes Traefik’s
metricsport:traefik_service_requests_totalandtraefik_service_request_duration_seconds, per backend service - so the canary’s requests are counted apart from the primary’s. Every 15 seconds, not 30: a canary’s first500creates a new series, andrate()sees a series only from its second sample. At 30 seconds the errors reached the analysis a minute late, and the broken release got to 30% instead of 20%. - Requests.
develophas no users.frontend-synthetic-trafficsends two requests a second through Traefik, over HTTPS, as users would: a page and an API call the frontend proxies. Only while the canary module is enabled. - No data is a failure. The first check after a canary starts usually finds nothing yet - no values found - and counts as a failed check. The next one has data. A canary that only ever finds nothing rolls every release back: the story.
At two requests a second, 10% is about twelve canary requests a minute. A 99% threshold on twelve requests is a coarse instrument - it catches three failures in ten, not one in a thousand. Real traffic makes the canary sharper; synthetic traffic keeps it from going blind.
Breaking a Release on Purpose
The lab needs a frontend release that fails for some users. RANDOM_ERROR_RATE - the same name and meaning as the backend’s in Chapter 15 - makes the frontend’s nginx answer 500 to that share of requests; /health is never failed, so the pods stay Ready and the errors reach users and the analysis, not the kubelet. An invalid value stops the container. scripts/check-app-security.sh refuses it in any production overlay.
Only the Frontend
The frontend holds no data: its rollback is the previous image. The backend owns a database. A canary of it runs two versions against one schema at once, so the schema must fit both - expand/contract (Chapter 18) - and the frontend’s calls to it would have to be split inside the cluster, which takes a mesh or a gateway. That is a chapter of its own.
What This Does Not Solve
This is one widely used approach - a canary split by requests, judged by metrics - not the whole field.
- Requests are split, not people. Traefik weighs every request on its own; nothing ties a browser to one version. One person can get the canary for one request and the primary for the next. What a canary limits is the share of requests a bad release gets, and for how long - not a group of users kept safe.
- A new frontend build can break the page in a way the analysis does not see. A Vite build names its JavaScript after its content (
/assets/index-<hash>.js), and each image holds only its own. While two versions serve, the page can come from one and its script from the other - which does not have that file:404, a blank page. The success rate counts only5xxas failures, and the synthetic traffic never loads a script, so such a release can pass. The lab’s releases change configuration, not the build, so they do not hit it. Real systems avoid it by serving every version’s assets from one place (an object store or CDN the build uploads to before the release), or by keeping a browser on one version (sticky sessions - Flagger offers them for Istio and the Gateway API, not for its Traefik provider). - Synthetic traffic, not users. It proves the analysis can see data, not that users are fine. A load tester that runs only during an analysis (Flagger’s webhooks) is the common alternative to a generator that runs all the time; this platform keeps one running so the metrics and the no-traffic alert have data between releases too.
Switching It On and Off
The module is opt-in: flux/bootstrap/flux-system/progressive-delivery-develop.yaml, added to that directory’s kustomization.yaml through a pull request. Switching it off removes it again; the Canary sets revertOnDeletion: true, so Flagger scales frontend back up and points the Service at it before it deletes frontend-primary. Without that, the Service would keep selecting pods that no longer exist. Note which version that is: frontend is what Git holds - after a rejected release, the rejected one. Flagger does not copy the healthy primary back. So the healthy version goes back into Git first, its analysis passes, and only then is the module switched off.
On the cloud cluster the module is not enabled yet: there, the IngressRoute’s certificate, the DNS record and Traefik’s metrics port are checked first.
Instructions for Your AI Agent
The rules this chapter adds:
- When a canary rolls a release back, find out why from its events and metrics - never lower the threshold, remove a metric or set
skipAnalysisto get the release through. Enforced by: the alertCanaryRolledBack; review of the Canary’s diff. - A failed check with no values is a broken analysis, not a bad release: fix the traffic or the metrics before the next release.
Enforced by:
frontend-synthetic-trafficand the Traefik PodMonitor in the monitoring stack; instruction. - A route made for a canary is a public route: never match an internal name on a public entrypoint. Enforced by: instruction; review.
RANDOM_ERROR_RATEis fordevelopand labs only. Enforced by:scripts/check-app-security.shin pre-commit and in the Flux Diff workflow.
This builds on: Observability (Chapter 11) - the error ratio of user requests - and Rollback and Data Migrations (Chapter 18): why only a service without data is this simple. This enables: Platform Lifecycle (Chapter 20) - upgrades of the platform’s own components, released and checked the same careful way.