Traffic Route

This policy allows us to configure routing rules for L4 traffic running in our Mesh. This policy provides support for wheighted routing and can be used to implement versioning across our services as well as deployment strategies like blue/green and canary.

Usage

By default when a service makes a request to another service, Kuma will round robin the request across every data plane proxy belogning to the destination service. It is possible to change this behavior by using this policy, for example:

  1. apiVersion: kuma.io/v1alpha1
  2. kind: TrafficRoute
  3. mesh: default
  4. metadata:
  5. namespace: default
  6. name: route-example
  7. spec:
  8. sources:
  9. - match:
  10. service: backend.default.svc:80
  11. destinations:
  12. - match:
  13. service: redis.default.svc:6379
  14. conf:
  15. - weight: 90
  16. destination:
  17. service: redis.default.svc:6379
  18. version: '1.0'
  19. - weight: 10
  20. destination:
  21. service: redis.default.svc:6379
  22. version: '2.0'

We will apply the configuration with kubectl apply -f [..].

  1. type: TrafficRoute
  2. name: route-example
  3. mesh: default
  4. sources:
  5. - match:
  6. service: backend
  7. destinations:
  8. - match:
  9. service: redis
  10. conf:
  11. - weight: 90
  12. destination:
  13. service: redis
  14. version: '1.0'
  15. - weight: 10
  16. destination:
  17. service: redis
  18. version: '2.0'

We will apply the configuration with kumactl apply -f [..] or via the HTTP API.

In this example the TrafficRoute policy assigns a positive weight of 90 to the version 1.0 of the redis service and a positive weight of 10 to the version 2.0 of the redis service.

Note that routing can be applied not just on the automatically provisioned service Kuma tag, but on any other tag that we may want to add to our data plane proxies (like version in the example above).

Kuma utilizes positive weights in the TrafficRoute policy and not percentages, therefore Kuma does not check if the total adds up to 100. If we want to stop sending traffic to a destination service we change the weight for that service to 0.