Bird
Raised Fist0
Kubernetesdevops~10 mins

Traffic management with Istio in Kubernetes - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a VirtualService that routes all traffic to the 'v1' version of the service.

Kubernetes
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-service
spec:
  hosts:
  - my-service
  http:
  - route:
    - destination:
        host: my-service
        subset: [1]
Drag options to blanks, or click blank then click option'
Av1
Bv2
Cv3
Dlatest
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a version that is not defined in the DestinationRule
Using 'latest' which is not a valid subset
2fill in blank
medium

Complete the code to define a DestinationRule that sets the subset 'v2' with the label 'version: v2'.

Kubernetes
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: my-service
spec:
  host: my-service
  subsets:
  - name: v2
    labels:
      [1]: v2
Drag options to blanks, or click blank then click option'
Aapp
Bversion
Cenv
Dtier
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app' or 'env' which are not used for version subsets
Leaving the label key empty
3fill in blank
hard

Fix the error in the VirtualService to split traffic 80% to 'v1' and 20% to 'v2'.

Kubernetes
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-service
spec:
  hosts:
  - my-service
  http:
  - route:
    - destination:
        host: my-service
        subset: v1
      weight: [1]
    - destination:
        host: my-service
        subset: v2
      weight: 20
Drag options to blanks, or click blank then click option'
A20
B50
C80
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Setting weight to 20 which duplicates 'v2' weight
Setting weight to 100 which sends all traffic to 'v1'
4fill in blank
hard

Fill both blanks to create a Gateway that listens on port 80 for HTTP traffic.

Kubernetes
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: my-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: [1]
      name: http
      protocol: [2]
    hosts:
    - "*"
Drag options to blanks, or click blank then click option'
A80
B443
CHTTP
DHTTPS
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 443 which is for HTTPS
Using protocol 'HTTPS' when port is 80
5fill in blank
hard

Fill all three blanks to create a VirtualService that uses the Gateway 'my-gateway' and routes traffic to subset 'v1' of 'my-service'.

Kubernetes
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-service
spec:
  hosts:
  - my-service
  gateways:
  - [1]
  http:
  - route:
    - destination:
        host: [2]
        subset: [3]
Drag options to blanks, or click blank then click option'
Amy-gateway
Bmy-service
Cv1
Ddefault
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'default' as subset which is not defined
Using wrong gateway or host names

Practice

(1/5)
1. What is the primary purpose of an Istio VirtualService in traffic management?
easy
A. To define how requests are routed to different versions of a service
B. To store persistent data for services
C. To monitor CPU usage of pods
D. To create Kubernetes namespaces

Solution

  1. Step 1: Understand VirtualService role

    An Istio VirtualService defines routing rules for directing traffic to services.
  2. Step 2: Compare options

    Only To define how requests are routed to different versions of a service describes routing traffic to different service versions, which is the main use of VirtualService.
  3. Final Answer:

    To define how requests are routed to different versions of a service -> Option A
  4. Quick Check:

    VirtualService controls routing = A [OK]
Hint: VirtualService controls routing rules, not storage or monitoring [OK]
Common Mistakes:
  • Confusing VirtualService with ConfigMap
  • Thinking VirtualService manages resource usage
  • Mixing VirtualService with namespace creation
2. Which of the following is the correct syntax to split 80% of traffic to version v1 and 20% to version v2 in an Istio VirtualService?
easy
A. weight: 80 version: v1 weight: 20 version: v2
B. route: - destination: host: myservice subset: v1 weight: 80 - destination: host: myservice subset: v2 weight: 20
C. trafficSplit: v1: 80 v2: 20
D. split: v1: 0.8 v2: 0.2

Solution

  1. Step 1: Recall Istio VirtualService traffic split syntax

    Traffic split uses route with destination and weight fields under each route.
  2. Step 2: Match syntax to options

    route: - destination: host: myservice subset: v1 weight: 80 - destination: host: myservice subset: v2 weight: 20 correctly shows route list with destination.host, subset, and weight keys.
  3. Final Answer:

    route: - destination: host: myservice subset: v1 weight: 80 - destination: host: myservice subset: v2 weight: 20 -> Option B
  4. Quick Check:

    Correct route and weight syntax = D [OK]
Hint: Look for 'route' with destination and weight keys [OK]
Common Mistakes:
  • Using invalid keys like 'trafficSplit' or 'split'
  • Missing 'destination' block
  • Incorrect indentation or missing dashes
3. Given this VirtualService snippet, what percentage of traffic goes to version v2?
route:
- destination:
    host: reviews
    subset: v1
  weight: 70
- destination:
    host: reviews
    subset: v2
  weight: 30
medium
A. 30%
B. 70%
C. 50%
D. 100%

Solution

  1. Step 1: Identify weights for each version

    Version v1 has weight 70, v2 has weight 30.
  2. Step 2: Calculate traffic percentage for v2

    Weight 30 means 30% of traffic is routed to v2.
  3. Final Answer:

    30% -> Option A
  4. Quick Check:

    Weight 30 means 30% traffic to v2 [OK]
Hint: Weight number equals traffic percentage [OK]
Common Mistakes:
  • Confusing weights as cumulative
  • Assuming equal split by default
  • Ignoring subset field
4. You wrote this VirtualService snippet but traffic is not splitting as expected:
route:
- destination:
    host: productpage
    subset: v1
  weight: 50
- destination:
    host: productpage
    subset: v2
  weight: 60
What is the error?
medium
A. Subset names must be uppercase
B. Missing 'http:' key before 'route'
C. Host name should be the service IP, not name
D. Weights sum to more than 100, causing misrouting

Solution

  1. Step 1: Check weights sum

    Weights are 50 and 60, totaling 110%, which is invalid.
  2. Step 2: Understand traffic split rules

    Weights must sum to 100 or less to properly split traffic.
  3. Final Answer:

    Weights sum to more than 100, causing misrouting -> Option D
  4. Quick Check:

    Weights > 100 cause errors [OK]
Hint: Sum weights to 100 or less for valid splits [OK]
Common Mistakes:
  • Ignoring total weight sum
  • Forgetting 'http:' key is optional but recommended
  • Thinking subset names are case sensitive
5. You want to route 100% of traffic from users with header version: v2 to version v2 of your service, and all others to v1. Which VirtualService configuration snippet achieves this?
hard
A. route: - destination: host: myservice subset: v1 weight: 50 - destination: host: myservice subset: v2 weight: 50
B. route: - destination: host: myservice subset: v2 weight: 100 headers: request: exact: {version: v2} - destination: host: myservice subset: v1 weight: 100
C. http: - match: headers: version: exact: v2 route: - destination: host: myservice subset: v2 - route: - destination: host: myservice subset: v1
D. http: - route: - destination: host: myservice subset: v2 weight: 100

Solution

  1. Step 1: Identify header-based routing syntax

    Istio uses http with match for header conditions.
  2. Step 2: Check options for header match and routing

    http: - match: headers: version: exact: v2 route: - destination: host: myservice subset: v2 - route: - destination: host: myservice subset: v1 correctly matches header version: v2 and routes to subset v2, else routes to v1.
  3. Final Answer:

    http: - match: headers: version: exact: v2 route: - destination: host: myservice subset: v2 - route: - destination: host: myservice subset: v1 -> Option C
  4. Quick Check:

    Header match with http and route = A [OK]
Hint: Use 'http' with 'match' for header-based routing [OK]
Common Mistakes:
  • Placing headers under route weight instead of match
  • Splitting traffic by weight instead of header
  • Omitting 'http:' block for routing rules