Technologies Available

istio

Traffic management

Service routes and version subsets should be in place given the destination rules applied in Lab 3. If they are not present, re-apply the destination rules:


1apiVersion: networking.istio.io/v1alpha3
2kind: DestinationRule
3metadata:
4 name: productpage
5spec:
6 host: productpage
7 subsets:
8 - name: v1
9 labels:
10 version: v1
11---
12
13apiVersion: networking.istio.io/v1alpha3
14kind: DestinationRule
15metadata:
16name: reviews
17spec:
18host: reviews
19subsets: - name: v1
20labels:
21version: v1 - name: v2
22labels:
23version: v2 - name: v3
24labels:
25version: v3
26
27---
28
29apiVersion: networking.istio.io/v1alpha3
30kind: DestinationRule
31metadata:
32name: ratings
33spec:
34host: ratings
35subsets: - name: v1
36labels:
37version: v1 - name: v2
38labels:
39version: v2 - name: v2-mysql
40labels:
41version: v2-mysql - name: v2-mysql-vm
42labels:
43version: v2-mysql-vm
44
45---
46
47apiVersion: networking.istio.io/v1alpha3
48kind: DestinationRule
49metadata:
50name: details
51spec:
52host: details
53subsets: - name: v1
54labels:
55version: v1 - name: v2
56labels:
57version: v2
58
59---

Start managing traffic routes

Some basics to get us started.

Send all requests to Productpage v1

1apiVersion: networking.istio.io/v1alpha3
2kind: VirtualService
3metadata:
4 name: reviews
5spec:
6 hosts:
7 - reviews
8 http:
9 - route:
10 - destination:
11 host: reviews
12 subset: v1

Using Meshery, apply custom configuration.

Refresh BookInfo productpage

Send all requests to Productpage v2

1apiVersion: networking.istio.io/v1alpha3
2kind: VirtualService
3metadata:
4 name: reviews
5spec:
6 hosts:
7 - reviews
8 http:
9 - route:
10 - destination:
11 host: reviews
12 subset: v2

Using Meshery, apply custom configuration.

Refresh BookInfo productpage.

Traffic routing based on user or user-agent type


Redirect requests from mobile devices

1apiVersion: networking.istio.io/v1alpha3
2kind: VirtualService
3metadata:
4 name: bookinfo
5spec:
6 hosts:
7 - "bookinfo.meshery.io"
8 gateways:
9 - sample-app-gateway
10 http:
11 - match:
12 - headers:
13 User-Agent:
14 regex: ^.*Mobile.*$
15 route:
16 - headers:
17 request:
18 set:
19 x-response: "Success with Mobile"
20 destination:
21 host: productpage
22 port:
23 number: 9080
24 - route:
25 - destination:
26 host: product
27 subset: random

Set your browser to mimic a mobile device. Enable Developer tools, if need. Refresh BookInfo productpage.

Redirect requests based on HTTP header information

Example of using user information from HTTP headers to redirect requests.

1apiVersion: networking.istio.io/v1alpha3
2kind: VirtualService
3metadata:
4 name: reviews
5spec:
6 hosts:
7 - reviews
8 http:
9 - match:
10 - headers:
11 end-user:
12 exact: naruto
13 route:
14 - destination:
15 host: reviews
16 subset: v2
17 - match:
18 - headers:
19 end-user:
20 exact: sasuke
21 route:
22 - destination:
23 host: reviews
24 subset: v3
25 - route:
26 - destination:
27 host: reviews
28 subset: v1

Traffic Mirroring with Istio

You will need to generate load on BookInfo's productpage service. See Lab 4 for instructions for running a performance test.

1apiVersion: networking.istio.io/v1alpha3
2kind: VirtualService
3metadata:
4 name: reviews
5spec:
6 hosts:
7 - reviews
8 http:
9 - route:
10 - destination:
11 host: reviews
12 subset: v1
13 weight: 100
14 mirror:
15 host: reviews
16 subset: v2
17 mirror_percent: 100

Incrementally increase the traffic split percentage to the higher version service #. Start at 20% traffic split

1apiVersion: networking.istio.io/v1alpha3
2kind: VirtualService
3metadata:
4 name: reviews
5spec:
6 hosts:
7 - reviews
8 http:
9 - route:
10 - destination:
11 host: reviews
12 subset: v1
13 weight: 80
14 - destination:
15 host: reviews
16 subset: v3
17 weight: 20

Move to 50%. Observe in Meshery.

1apiVersion: networking.istio.io/v1alpha3
2kind: VirtualService
3metadata:
4 name: reviews
5spec:
6 hosts:
7 - reviews
8 http:
9 - route:
10 - destination:
11 host: reviews
12 subset: v1
13 weight: 50
14 - destination:
15 host: reviews
16 subset: v3
17 weight: 50

Injecting Latency

Acknowledging the fallacy that the network is always reliable, you will intentionally cause a little chaos.

Exploring timeouts with Reviews service

Note Istio Proxy's default timeout settings.

1
2---
3apiVersion: networking.istio.io/v1alpha3
4kind: VirtualService
5metadata:
6 name: reviews
7spec:
8 hosts:
9 - reviews
10 http:
11 - match:
12 - headers:
13 end-user:
14 exact: naruto
15 fault:
16 delay:
17 percentage:
18 value: 100.0
19 fixedDelay: 11s
20 route:
21 - destination:
22 host: reviews
23 subset: v1
24 - route:
25 - destination:
26 host: reviews
27 subset: v2

Exploring timeouts with Ratings service

1
2---
3apiVersion: networking.istio.io/v1alpha3
4kind: VirtualService
5metadata:
6 name: ratings
7spec:
8 hosts:
9 - ratings
10 http:
11 - match:
12 - headers:
13 end-user:
14 exact: naruto
15 fault:
16 delay:
17 percentage:
18 value: 100.0
19 fixedDelay: 5s
20 route:
21 - destination:
22 host: ratings
23 subset: v1
24 - route:
25 - destination:
26 host: ratings
27 subset: v1

Retries

Overcoming the latency issue.

Set 5 retry attempts and a 3 second timeout

1apiVersion: networking.istio.io/v1alpha3
2kind: VirtualService
3metadata:
4 name: reviews
5spec:
6 hosts:
7 - reviews
8 http:
9 - route:
10 - destination:
11 host: reviews
12 subset: v1
13 retries:
14 attempts: 5
15 perTryTimeout: 3s

Alternative: Manual installation

Follow these steps if the above steps did not work



Traffic management with Istio

If you haven't forked or cloned this repository, please do so now:

git clone https://github.com/layer5io/advanced-istio-service-mesh-workshop

Route all traffic to version V1

kubectl apply -f route-v1-v2/v1.yaml

Route all traffic to version V2

kubectl apply -f route-v1-v2/v2.yaml

Traffic routing based on user or user-agent type

Redirect requests from mobile devices

kubectl apply -f route-header/device.yaml

Redirect requests based on Cookie data

kubectl apply -f route-header/user.yaml

NEXT CHAPTER

Getting Started

Layer5 is the steward of Meshery and creator of Kanvas, the collaborative canvas for cloud-native infrastructure. We bridge the gap between design and operation, allowing engineers to create, configure, and deploy orchestratable diagrams in real time. Whether managing Kubernetes or multi-cloud environments, Layer5 provides the tooling needed to oversee modern infrastructure with confidence.