# Flagger Kubernetes: Designing Production-Ready Canary Releases

Adding progressive delivery to an existing Kubernetes platform involves more than choosing a controller.

The release policy, traffic layer, observability system and GitOps workflow must all cooperate.

Flagger provides an interesting approach because teams can introduce automated canary analysis around their existing Deployment resources.

## The architecture

Consider a checkout service running on Kubernetes.

A deployment pipeline introduces a new application image, while the current primary version continues serving production requests.

Flagger coordinates four main responsibilities:

- Preparing the candidate application revision.
- Managing traffic distribution.
- Evaluating application signals.
- Deciding whether to promote or reject the release.

With Gateway API, the traffic distribution is represented through HTTPRoute backend weights.

## Designing the release policy

A typical analysis configuration looks like this:

```yaml
analysis:
  interval: 30s
  threshold: 3
  maxWeight: 50
  stepWeight: 10
```

This is only an analysis fragment. A complete Canary also needs the workload and service configuration.

A larger traffic increment makes releases progress more quickly but exposes more requests to an insufficiently tested version.

Smaller increments reduce exposure at each step but may extend the release process.

Neither strategy is automatically correct. The appropriate policy depends on service traffic, business criticality and metric quality.

## Building reliable metric checks

Flagger supports custom MetricTemplates that connect application measurements to release decisions.

An HTTP success-rate query might use a metric named `http_requests_total`.

For example:

```promql
100 *
sum(rate(http_requests_total{
  namespace="staging",
  app="checkout-api",
  status!~"5.*"
}[1m]))
/
sum(rate(http_requests_total{
  namespace="staging",
  app="checkout-api"
}[1m]))
```

This example assumes those labels identify only the canary workload and that the application exposes the specified metric.

Validate both assumptions before using it.

Also note that this query measures non-5xx responses, not necessarily successful business transactions.

An application can return HTTP 200 while failing to complete an order correctly.

That is why production release gates should consider business-level signals where appropriate.

## Dealing with insufficient traffic

A metric is meaningful only when enough observations exist.

A canary that receives very few requests may not reveal intermittent errors.

Useful approaches include:

- Minimum request-volume checks.
- Synthetic traffic through a load-testing webhook.
- Suitable analysis intervals.
- Explicit treatment of missing and non-finite metric results.

Test these conditions in staging rather than assuming the monitoring system will handle them correctly.

## GitOps ownership boundaries

When Flux or another GitOps system manages the desired application state, avoid conflicting ownership with Flagger.

The platform repository should define the original application workload, the Canary configuration and the metric policies.

Flagger manages the generated primary workload and related routing resources.

If GitOps continually restores replica counts or overwrites generated routing weights, controllers may work against each other.

Configure reconciliation and autoscaling deliberately.

## Rollback is not a universal undo operation

Automated traffic rollback is valuable, but it does not reverse every action performed by the application.

Consider a new release that modifies a database schema or sends messages to an external system.

Returning traffic to the previous version does not necessarily reverse those changes.

Backward-compatible database migrations and idempotent operations remain important.

## Flagger or Argo Rollouts?

Both tools can automate progressive delivery.

Flagger is attractive when a platform already has many standard Deployments and wants a separate Canary policy.

Argo Rollouts provides a dedicated Rollout resource with explicit release steps and analysis integration.

Choose based on workload ownership, routing integrations, operational requirements and migration effort rather than assuming one tool is universally superior.

## Production checklist

Before enabling automated promotion:

- Validate canary-specific telemetry.
- Verify Gateway and HTTPRoute attachment.
- Test failure thresholds.
- Confirm GitOps ownership boundaries.
- Configure appropriate alerting.
- Exercise rollback in staging.
- Review database compatibility.

Progressive delivery is ultimately a controlled way of increasing confidence in a new release.

For a full implementation walkthrough with Helm commands, Canary YAML, MetricTemplates and common troubleshooting scenarios, see the [original Flagger Kubernetes guide](https://blog.naveedkumbhar.com/flagger-kubernetes-guide/).
