Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

A/B Testing With Kubernetes and Istio

DZone's Guide to

A/B Testing With Kubernetes and Istio

See how you can use Kubernetes and Istio together to implement A/B testing in your app so that you can measure user response and make the best decisions.

· Microservices Zone ·
Free Resource

The new Gartner Critical Capabilities report explains how APIs and microservices enable digital leaders to deliver better B2B, open banking and mobile projects.

Last week I gave a presentation “When to use Serverless? When to use Kubernetes?” One of the weaknesses of Serverless platforms is that you currently cannot do things like A/B testing well since there is no notion of versions.

A/B testing allows running multiple variants of functionality in parallel, so that through analytics of user behavior, the better variant can be determined. Similar to ‘dark launches,’ new features can be made available to only certain users to test features in production environments before these features will be released to the masses.

These traffic flow management capabilities are one of the advantages of Kubernetes and Istio. Istio is an open platform to manage microservices.

Some of my colleagues have documented how to do traffic flow management with Istio for the Book Info sample that is part of the Istio documentation. The current documentation is for Istio 0.1.6 and doesn’t work for the later version 0.5.0, which I use. I’ve sent a pull request, since some URLs have changed.

The diagram shows the architecture of the book info sample app. Books have reviews and can have ratings. The application has three versions of the review service. The gray components on the left-hand side are the Istio components. When the sample application is deployed, further Istio components, the Envoy containers, are automatically added to each pod. These Envoy components are proxies (also called sidecars) through which containers communicate with each other which is the basis for Istio’s traffic management capabilities.

istio-sample-architecture

Check out the bookinfo.yaml file to see how to define and deploy the three versions of the review service.

In order to route traffic to version 1 for 50% of the invocations and to version 3 for the other half, this route rule can be used.

apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
  name: reviews-default
spec:
  destination:
    name: reviews
  precedence: 1
  route:
  - labels:
      version: v1
    weight: 50
  - labels:
      version: v3
    weight: 50


In order to expose version 2 to only users with the name ‘Jason’, a regular expression can be used.

apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
  name: reviews-test-v2
spec:
  destination:
    name: reviews
  precedence: 2
  match:
    request:
      headers:
        cookie:
          regex: "^(.*?;)?(user=jason)(;.*)?$"
  route:
  - labels:
      version: v2


To learn more about traffic management in Istio, check out the documentation. If you want to try out Kubernetes, you can get an account on the IBM Cloud.

The new Gartner Critical Capabilities for Full Lifecycle API Management report shows how CA Technologies helps digital leaders with their B2B, open banking, and mobile initiatives. Get your copy from CA Technologies.

Topics:
microservices ,ab testing ,kubernetes ,istio ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}