Istio A/B Testing

This guide shows you how to automate A/B testing with Istio and Flagger.

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

Prerequisites

Flagger requires a Kubernetes cluster v1.16 or newer and Istio v1.0 or newer.

Install Istio with telemetry support and Prometheus:

Install Flagger in the istio-system namespace:

Create an ingress gateway to expose the demo app outside of the mesh:

Bootstrap

Create a test namespace with Istio sidecar injection enabled:

Create a deployment and a horizontal pod autoscaler:

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

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

Note that when using Istio 1.5 you have to replace the request-duration with a metric template.

The above configuration will run an analysis for ten minutes targeting Firefox users and those that have an insider cookie.

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

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

Automated canary promotion

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 Flagger's rollback.

Generate HTTP 500 errors:

Generate 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.

The above procedure can be extended with custom metrics checks, webhooks, manual promotion approval and Slack or MS Teams notifications.

Last updated

Was this helpful?