DEV Community

Cover image for Flagger Kubernetes: Automating Canary Releases with Gateway API
Naveed Ahmed
Naveed Ahmed

Posted on Originally published at blog.naveedkumbhar.com

Flagger Kubernetes: Automating Canary Releases with Gateway API

Flagger Kubernetes: Automating Canary Releases with Gateway API

Kubernetes Deployments are excellent at managing application replicas.

But what happens when every Pod becomes Ready and the new application version still produces errors?

Readiness checks alone cannot represent every aspect of application health.

Flagger addresses this problem by introducing automated release analysis.

What is Flagger?

Flagger is a progressive delivery controller from the Flux ecosystem.

It manages the release process around existing Kubernetes workloads using a Canary custom resource.

For a typical Deployment-based rollout, Flagger maintains a primary Deployment that handles stable production traffic. The original Deployment becomes the target used to evaluate new revisions.

A release is promoted only after satisfying the configured checks, unless analysis has explicitly been bypassed.

Prerequisites

For the Gateway API example, you need:

  • A Kubernetes cluster.
  • Helm and kubectl.
  • Gateway API CRDs.
  • A compatible Gateway API controller.
  • A configured Gateway.
  • Prometheus with relevant application telemetry.
  • An application Deployment to manage.

Use a staging cluster for your initial experiments.

Installing Flagger

Add the Helm repository:

helm repo add flagger https://flagger.app
helm repo update
Enter fullscreen mode Exit fullscreen mode

Example installation:

helm upgrade --install flagger flagger/flagger \
  --namespace flagger-system \
  --create-namespace \
  --set meshProvider=gatewayapi:v1 \
  --set metricsServer=http://prometheus-operated.monitoring.svc:9090
Enter fullscreen mode Exit fullscreen mode

Replace the Prometheus endpoint with your actual service address.

For production, pin a tested Helm chart version rather than relying on an unpinned installation.

Verify the controller:

kubectl rollout status deployment/flagger \
  -n flagger-system --timeout=2m

kubectl get crds | grep flagger.app
Enter fullscreen mode Exit fullscreen mode

Defining a Canary resource

A Canary resource connects the application workload to the release policy.

The following is an illustrative configuration adapted for a staging environment:

apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
  name: checkout-api
  namespace: staging
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: checkout-api
  progressDeadlineSeconds: 600
  service:
    port: 80
    targetPort: 8080
    hosts:
      - checkout.example.com
    gatewayRefs:
      - name: shared-gateway
        namespace: gateway-system
  analysis:
    interval: 30s
    threshold: 3
    maxWeight: 50
    stepWeight: 10
    metrics:
      - name: http-success-rate
        templateRef:
          name: http-success-rate
          namespace: flagger-system
        thresholdRange:
          min: 99.5
        interval: 30s
Enter fullscreen mode Exit fullscreen mode

This example assumes the Deployment, Gateway and referenced MetricTemplate already exist. The Gateway must allow routes from the staging namespace.

The threshold is illustrative rather than a universal production recommendation.

Understanding the analysis policy

The configuration defines four important values:

  • interval: how frequently analysis is scheduled.
  • threshold: the failed-check limit.
  • stepWeight: the traffic increment.
  • maxWeight: the maximum canary weight during analysis.

When checks succeed, the canary receives progressively more traffic.

When failures reach the configured limit, Flagger can stop the analysis and return traffic to the stable version.

Using Gateway API

Flagger can manage HTTPRoute backend weights through the Gateway API provider.

A possible intermediate traffic distribution is:

Primary service: 90%
Canary service: 10%
Enter fullscreen mode Exit fullscreen mode

After successful checks:

Primary service: 80%
Canary service: 20%
Enter fullscreen mode Exit fullscreen mode

These weights represent relative routing proportions, not a guarantee of exact request counts.

The generated HTTPRoute is controller-managed state. Avoid having a separate GitOps configuration continuously overwrite it.

Prometheus metrics

A MetricTemplate defines the query Flagger uses to evaluate an application signal.

Useful checks include:

  • HTTP success rate.
  • Response latency.
  • Request volume.
  • Application-specific health indicators.

Always verify that the query selects the canary workload rather than combining primary and canary traffic.

A healthy primary can otherwise hide a failing new version.

Low-traffic services may also need synthetic traffic or an explicit minimum-volume check.

Watching a release

Use these read-only commands to inspect an existing Canary:

kubectl get canary -n staging

kubectl describe canary checkout-api \
  -n staging

kubectl logs deployment/flagger \
  -n flagger-system --tail=200

kubectl get httproute checkout-api \
  -n staging -o yaml
Enter fullscreen mode Exit fullscreen mode

The Canary events, controller logs and HTTPRoute status provide useful clues when a release stops advancing.

What happens during rollback?

If the weighted canary release exceeds its permitted failure count, Flagger returns application traffic to the primary service and scales down the unsuccessful candidate.

That does not automatically undo database migrations, external API calls or other persistent side effects.

Those require their own compatibility and recovery strategies.

Final thoughts

Progressive delivery makes application rollout decisions more measurable.

The important part is not simply installing a controller. It is defining reliable signals that demonstrate whether the new version deserves more traffic.

For the complete production guide, including MetricTemplates, Helm configuration, Argo Rollouts comparisons and troubleshooting examples, read the original Flagger Kubernetes guide.

Additional reference: Official Flagger Gateway API tutorial.

Top comments (0)