CodeBlanks Logo Icon CodeBlanks

Challenge - Istio

Write traffic routing with a VirtualService.

Challenge: a canary release

In this challenge you'll roll out the new version of the api service gradually with Istio. There are two deployments: labelled version: v1 and version: v2. The goal:

90% of traffic   -> v1
10% of traffic   -> v2
requests with the "x-test: evet" header -> always v2

First you'll define the subsets with a DestinationRule, then write the routing with a VirtualService.

Practice DestinationRule

Write a DestinationRule YAML: networking.istio.io/v1; name api; host: api; under subsets, name: v1 (labels: version: v1) and name: v2 (labels: version: v2).

Starter code

terminal
# buraya yaz

Sample solution

terminal
apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
  name: api
spec:
  host: api
  subsets:
    - name: v1
      labels:
        version: v1
    - name: v2
      labels:
        version: v2

Expected output

destinationrule.networking.istio.io/api created

Practice VirtualService

Write a VirtualService's http section (starting with http:): the first rule sends requests with headers: x-test: exact: evet under match to host: api, subset: v2; the second rule, with route, gives weight: 90 to v1 and weight: 10 to v2.

Starter code

terminal
# buraya yaz

Sample solution

terminal
http:
  - match:
      - headers:
          x-test:
            exact: evet
    route:
      - destination:
          host: api
          subset: v2
  - route:
      - destination:
          host: api
          subset: v1
        weight: 90
      - destination:
          host: api
          subset: v2
        weight: 10

Expected output

virtualservice.networking.istio.io/api configured
$ for i in $(seq 100); do curl -s http://api/surum; done | sort | uniq -c
     91 v1
      9 v2

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Should the header rule be written before the weighted rule in the VirtualService?

  • The weighted rule always comes first
  • They can't be in the same rule
  • Yes; http rules are tried in order, the first match applies Correct answer
  • No; order doesn't matter

Explanation: The weighted rule catches every request since it has no match condition.

2 Write the label selecting the subset.

Question
  subsets:
    - name: v2
      labels:
        ____: v2
Answer
  subsets:
    - name: v2
      labels:
        version: v2

Explanation: A subset is defined by pod labels.

3 Match.

Term Meaning
DestinationRule Subsets
VirtualService Routing
weight Traffic share
match.headers Select by header

All lessons in Expert