Traffic management
- Docker & Kubernetes course
- Expert
- Lesson 22/47
- 4 min
Learn traffic routing with Istio.
Traffic management
Istio manages traffic with two objects: a DestinationRule defines a service's subsets (e.g. versions) and connection settings; a VirtualService determines which subset requests go to and in what proportion. For a canary deployment, the new version gets a small percentage of the traffic:
apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
name: api
spec:
host: api
subsets:
- name: v1
labels: {surum: v1}
- name: v2
labels: {surum: v2}
---
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: api
spec:
hosts: [api]
http:
- route:
- destination: {host: api, subset: v1}
weight: 90
- destination: {host: api, subset: v2}
weight: 10Resilience settings
The VirtualService defines retries and timeouts; the DestinationRule defines circuit breaking (taking an instance returning too many errors out of rotation for a while):
# VirtualService
http:
- route: [{destination: {host: api, subset: v1}}]
timeout: 3s
retries:
attempts: 3
perTryTimeout: 1s
retryOn: 5xx,reset,connect-failure
# DestinationRule
trafficPolicy:
outlierDetection:
consecutive5xxErrors: 5
interval: 30s
baseEjectionTime: 60sPractice Canary routing
Write a VirtualService's spec section (starting with spec:): hosts: [api]; a single route under http: weight: 80 to api/v1, weight: 20 to api/v2; timeout: 3s.
Starter code
# buraya yazSample solution
spec:
hosts: [api]
http:
- route:
- destination:
host: api
subset: v1
weight: 80
- destination:
host: api
subset: v2
weight: 20
timeout: 3sExpected output
virtualservice.networking.istio.io/api configured
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Without a mesh, how is the ratio set when doing a canary with two Deployments?
- Randomly
- With a Service weight
- It isn't possible
- By the ratio of replica counts (e.g. 9:1); with a mesh, a percentage independent of replicas is given Correct answer
Explanation: A Kubernetes Service has no weight field.
2 Write the share of traffic going to the new version.
- destination: {host: api, subset: v2}
____: 10
- destination: {host: api, subset: v2}
weight: 10
Explanation: The weights must sum to 100.
3 Match.
| Term | Meaning |
|---|---|
DestinationRule |
Subsets and policy |
VirtualService |
Routing rules |
weight |
Traffic share |
outlierDetection |
Circuit breaker |