RousselTMLEARNING

Proxy & networking

Automated canary with Flagger and Traefik on Kubernetes

Automate canary deployments with Flagger and Traefik: the Canary resource, Prometheus metric analysis, weight progression, automatic promotion or rollback, test webhooks.

1. The principle #

Canary without human intervention.

How it works #

Flagger is a Kubernetes progressive delivery operator. From a Deployment, it creates a primary (stable) version and a canary version, then drives a weighted TraefikService. With each new image, it gradually increases the canary's share of traffic as long as the metrics stay good, then promotes it; otherwise it rolls back.

Flagger canary analysis
Decisions are based on Prometheus metrics, not on a human operator.

2. Installation and the Canary resource #

Flagger with the Traefik provider.

Installation #

helm repo add flagger https://flagger.app
helm upgrade --install flagger flagger/flagger -n traefik \
  --set meshProvider=traefik \
  --set metricsServer=http://prometheus.monitoring:9090

Canary #

apiVersion: flagger.app/v1beta1
kind: Canary
metadata: { name: app, namespace: app }
spec:
  provider: traefik
  targetRef: { apiVersion: apps/v1, kind: Deployment, name: app }
  service: { port: 80, targetPort: 8080 }
  analysis:
    interval: 1m
    threshold: 5                 # 5 analyses en échec = retour arrière
    maxWeight: 50
    stepWeight: 10
    metrics:
      - name: request-success-rate
        thresholdRange: { min: 99 }
        interval: 1m
      - name: request-duration
        thresholdRange: { max: 500 }   # millisecondes
        interval: 1m
    webhooks:
      - name: tests-de-fumee
        type: pre-rollout
        url: http://flagger-loadtester.app/
        metadata: { cmd: "curl -sf http://app-canary.app/healthz" }

3. Following and triggering #

Day to day.

Commands #

kubectl -n app set image deploy/app app=registre/app:2.1.0   # déclenche une analyse
kubectl -n app get canary app -w                                # Progressing, Succeeded, Failed
kubectl -n app describe canary app                              # événements : poids, métriques, décisions
kubectl -n app get traefikservice
  • Generate traffic during the analysis (loadtester): without requests, metrics are empty and the analysis fails.
  • Choose thresholds aligned with your SLOs.
  • Send Flagger events to the team's channel (Slack or Teams alerting).
Good practice: Start with a non-critical service and observe several deployments before rolling it out more widely.

Related articles

Traefik: securing and transforming requests with middlewares (BasicAuth, ForwardAuth…)

Traefik middlewares modify requests and responses between the router and the service: BasicAuth and ForwardAu…

Traefik: providers (Docker, Kubernetes, Nomad, Consul, files, key-value stores)

Providers feed Traefik's dynamic configuration: service discovery for Docker, Swarm, Kubernetes, Nomad and Co…

Traefik as an Ingress Controller for Kubernetes (Helm, IngressRoute, Gateway API)

Install Traefik in Kubernetes with Helm and publish applications with Ingress, the IngressRoute and Middlewar…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!