Canary analysis with Prometheus Operator

This guide show you how to use Prometheus Operator for canary analysis.

Prerequisites

Flagger requires a Kubernetes cluster v1.16 or newer and Prometheus Operator v0.40 or newer.

Install Prometheus Operator with Helm v3:

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

kubectl create ns monitoring
helm upgrade -i prometheus prometheus-community/kube-prometheus-stack \
--namespace monitoring \
--set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false \
--set fullnameOverride=prometheus

The prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false option allows Prometheus Operator to watch serviceMonitors outside of its namespace.

Install Flagger by setting the metrics server to Prometheus:

helm repo add flagger https://flagger.app

kubectl create ns flagger-system
helm upgrade -i flagger flagger/flagger \
--namespace flagger-system \
--set metricsServer=http://prometheus-prometheus.monitoring:9090 \
--set meshProvider=kubernetes

Install Flagger's tester:

Install podinfo demo app:

Service monitors

The demo app is instrumented with Prometheus, so you can create a ServiceMonitor objects to scrape podinfo's metrics endpoint:

We are setting interval: 5s to have a more aggressive scraping. If you do not define it, you should use a longer interval in the Canary object.

Metric templates

Create a metric template to measure the HTTP requests error rate:

Create a metric template to measure the HTTP requests average duration:

Canary analysis

Using the metrics template you can configure the canary analysis with HTTP error rate and latency checks:

Based on the above specification, Flagger creates the primary and canary Kubernetes ClusterIP service.

During the canary analysis, Prometheus will scrape the canary service and Flagger will use the HTTP error rate and latency queries to determine if the release should be promoted or rolled back.

Last updated

Was this helpful?