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

Exploring timeouts with Ratings service

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

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

Route all traffic to version V1

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

Route all traffic to version V2

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

Traffic routing based on user or user-agent type

Redirect requests from mobile devices

1kubectl apply -f route-header/device.yaml

Redirect requests based on Cookie data

1kubectl apply -f route-header/user.yaml

NEXT CHAPTER

Getting Started

Layer5, the cloud native management company