Gloo Canary Deployments

This guide shows you how to use the Gloo Edge ingress controller and Flagger to automate canary releases and A/B testing.

Flagger Gloo Ingress Controller

Prerequisites

Flagger requires a Kubernetes cluster v1.16 or newer and Gloo Edge ingress 1.6.0 or newer.

This guide was written for Flagger version 1.6.0 or higher. Prior versions of Flagger used Gloo UpstreamGroups to handle canaries, but newer versions of Flagger use Gloo RouteTables to handle canaries as well as A/B testing.

Install Gloo with Helm v3:

Install Flagger and the Prometheus add-on in the same namespace as Gloo:

Bootstrap

Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler (HPA), then creates a series of objects (Kubernetes deployments, ClusterIP services, Gloo route tables and upstreams). These objects expose the application outside the cluster and drive the canary analysis and promotion.

Create a test namespace:

Create a deployment and a horizontal pod autoscaler:

Deploy the load testing service to generate traffic during the canary analysis:

Create a virtual service definition that references a route table that will be generated by Flagger (replace app.example.com with your own domain):

Save the above resource as podinfo-virtualservice.yaml and then apply it:

Create a canary custom resource (replace app.example.com with your own domain):

Note: when using upstreamRef the following fields are copied over from the original upstream: Labels, SslConfig, CircuitBreakers, ConnectionConfig, UseHttp2, InitialStreamWindowSize

Save the above resource as podinfo-canary.yaml and then apply it:

After a couple of seconds Flagger will create the canary objects:

When the bootstrap finishes Flagger will set the canary status to initialized:

Automated canary promotion

Flagger implements a control loop that gradually shifts traffic to the canary while measuring key performance indicators like HTTP requests success rate, requests average duration and pod health. Based on analysis of the KPIs a canary is promoted or aborted, and the analysis result is published to Slack.

Flagger Canary Stages

Trigger a canary deployment by updating the container image:

Flagger detects that the deployment revision changed and starts a new rollout:

Note that if you apply new changes to the deployment during the canary analysis, Flagger will restart the analysis.

You can monitor all canaries with:

Automated rollback

During the canary analysis you can generate HTTP 500 errors and high latency to test if Flagger pauses and rolls back the faulted version.

Trigger another canary deployment:

Generate HTTP 500 errors:

Generate high latency:

When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, the canary is scaled to zero and the rollout is marked as failed.

Custom metrics

The canary analysis can be extended with Prometheus queries.

The demo app is instrumented with Prometheus so you can create a custom check that will use the HTTP request duration histogram to validate the canary.

Create a metric template and apply it on the cluster:

Edit the canary analysis and add the following metric:

The above configuration validates the canary by checking if the HTTP 404 req/sec percentage is below 5 percent of the total traffic. If the 404s rate reaches the 5% threshold, then the canary fails.

Trigger a canary deployment by updating the container image:

Generate 404s:

Watch Flagger logs:

If you have alerting configured, Flagger will send a notification with the reason why the canary failed.

A/B Testing

Besides weighted routing, Flagger can be configured to route traffic to the canary based on HTTP match conditions. In an A/B testing scenario, you'll be using HTTP headers or cookies to target a certain segment of your users. This is particularly useful for frontend applications that require session affinity.

Flagger A/B Testing Stages

Edit the canary analysis, remove the max/step weight and add the match conditions and iterations:

The above configuration will run an analysis for ten minutes targeting users that have a X-Canary: insider header.

Trigger a canary deployment by updating the container image:

Flagger detects that the deployment revision changed and starts the A/B test:

The web browser user agent header allows user segmentation based on device or OS.

For example, if you want to route all mobile users to the canary instance:

Or if you want to target only Android users:

Or a specific browser version:

For an in-depth look at the analysis process read the usage docs.

Last updated

Was this helpful?