Control the flow of your application with Istio

As a developers, we want our applications to perform as efficient as possible with the least number of issues. Traffic management is unquestionable feature to achieve that. Istio provides a set of configuration rules that allows you to control the flow of traffic. You can route the traffic basing on request's content or just split it percentage-based. You can test your application failure recovery abilities with Istio fault injection. There are plenty of other useful properties as circuit breaking, timeouts, retries or mirroring.


Let's take a look at few examples. All of these samples base on this repo.

Our network consists of two services: server and two versions of bot. All of the subsets should be defined in destination rule.

Request routing

This rule routes all traffic to v1 of bot service.

kind: VirtualService
metadata:
  name: bot
spec:
  hosts:
  - bot
  http:
  - route:
    - destination:
        host: bot
        subset: v1

We can also route traffic basing on request-content. Below example redirects the request with header user with value jason to v2 of bot service.

kind: VirtualService
metadata:
  name: bot
spec:
  hosts:
    - bot
  http:
  - match:
    - headers:
        user:
          exact: jason
    route:
    - destination:
        host: bot
        subset: v2
  - route:
    - destination:
        host: bot
        subset: v1

Fault injection

This example inserts 5s delay to 30 percent of request.

kind: VirtualService
metadata:
  name: bot
spec:
  hosts:
    - bot
  http:
  - route:
    - destination:
        host: bot
        subset: v1
    fault:
      delay:
        fixedDelay: 5s
        percent: 30

Retries

If HTTP request for v2 of bot service fails, Istio will execute 3 more attempts to connect.

kind: VirtualService
metadata:
  name: bot
spec:
  hosts:
    - bot
  http:
  - match:
    - headers:
        user:
          exact: jason
    route:
    - destination:
        host: bot
        subset: v2
    retries:
      attempts: 3
      perTryTimeout: 2s
  - route:
    - destination:
        host: bot
        subset: v1

Mirroring

All the traffic sent to v1 is mirrored to v2.

kind: VirtualService
metadata:
  name: bot
spec:
  hosts:
    - bot
  http:
  - route:
    - destination:
        host: bot
        subset: v1
      weight: 100
    mirror:
      host: bot
      subset: v2

As you can see, configuring traffic flow with Istio is trivially easy. It takes a little effort, but gives a lot of benefits. With traffic control, you can make your network more reliable and decrease a chance of future issues.