jonahkh
2020-05-13 4829e49af4e2cd4d8c8dfe0c215bd9f3d65efdfb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
= Advanced Route Rules
include::_attributes.adoc[]
 
[IMPORTANT]
.Before Start
====
You should have NO virtualservice nor destinationrule (in `tutorial` namespace) `kubectl get virtualservice{namespace-suffix}` `kubectl get destinationrule{namespace-suffix}` 
if so run:
 
[source, bash,subs="+macros,+attributes"]
----
./scripts/clean.sh tutorial{namespace-suffix}
----
====
 
[#canarydeploymentuseragent]
== Smart routing based on user-agent header (Canary Deployment)
 
What is your user-agent?
 
https://www.whoishostingthis.com/tools/user-agent/[https://www.whoishostingthis.com/tools/user-agent/]
 
Note: the "user-agent" header is added to OpenTracing baggage in the Customer service. From
there it is automatically propagated to all downstream services. To enable automatic
baggage propagation all intermediate services have to be instrumented with OpenTracing.
The baggage header for user agent has following form `baggage-user-agent: <value>`.
 
[#alltorecommendationv1]
=== Set recommendation to all v1
 
[source,bash,subs="+macros,+attributes"]
----
kubectl create -f link:{github-repo}/{istiofiles-dir}/destination-rule-recommendation-v1-v2.yml[istiofiles/destination-rule-recommendation-v1-v2.yml] -n tutorial{namespace-suffix}
kubectl create -f link:{github-repo}/{istiofiles-dir}/virtual-service-recommendation-v1.yml[istiofiles/virtual-service-recommendation-v1.yml] -n tutorial{namespace-suffix}
----
 
[#safaritov2]
=== Set Safari users to v2
 
[source,bash,subs="+macros,+attributes"]
----
kubectl replace -f link:{github-repo}/{istiofiles-dir}/virtual-service-safari-recommendation-v2.yml[istiofiles/virtual-service-safari-recommendation-v2.yml] -n tutorial{namespace-suffix}
 
kubectl get virtualservice -n tutorial{namespace-suffix}
----
 
and test with a Safari (or even Chrome on Mac since it includes Safari in the string). Safari only sees v2 responses from recommendation
 
and test with a Firefox browser, it should only see v1 responses from recommendation.
 
There are two ways to get the URL for your browser:
 
Open the url http://istio-ingressgateway-istio-system.{appdomain} in your broswer 
 
You can also attempt to use the curl -A command to test with different user-agent strings. 
 
[source,bash,subs="+macros,+attributes"]
----
curl -A Safari istio-ingressgateway-istio-system.{appdomain}/{path}
curl -A Firefox istio-ingressgateway-istio-system.{appdomain}/{path}
----
 
You can describe the virtualservice to see its configuration
 
[source,bash,subs="+macros,+attributes"]
----
kubectl get virtualservice -o yaml -n tutorial{namespace-suffix}
----
 
==== Remove the Safari rule
 
[source,bash,subs="+macros,+attributes"]
----
kubectl delete -f istiofiles/virtual-service-safari-recommendation-v2.yml -n tutorial{namespace-suffix}
----
 
[#mobiletov2]
=== Set mobile users to v2
 
[source,bash,subs="+macros,+attributes"]
----
kubectl create -f link:{github-repo}/{istiofiles-dir}/virtual-service-mobile-recommendation-v2.yml[istiofiles/virtual-service-mobile-recommendation-v2.yml] -n tutorial{namespace-suffix}
 
curl -A "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4(KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5" http://istio-ingressgateway-istio-system.{appdomain}/{path}
----
 
==== Clean up
 
[source,bash,subs="+macros,+attributes"]
----
kubectl delete -f istiofiles/destination-rule-recommendation-v1-v2.yml -n tutorial{namespace-suffix}
kubectl delete -f istiofiles/virtual-service-mobile-recommendation-v2.yml -n tutorial{namespace-suffix}
----
 
or you can run:
 
[source, bash,subs="+macros,+attributes"]
----
./scripts/clean.sh tutorial{namespace-suffix}
----
 
 
[#mirroringtraffic]
== Mirroring Traffic (Dark Launch)
 
[source,bash,subs="+macros,+attributes"]
----
oc get pods -l app=recommendation -n tutorial{namespace-suffix}
or 
kubectl get pods -l app=recommendation -n tutorial{namespace-suffix}
----
 
You should have 2 pods for recommendation based on the steps above
 
[source,bash,subs="+macros,+attributes"]
----
kubectl get virtualservice -n tutorial{namespace-suffix}
kubectl get destinationrule
----
 
 
You should have NO virtualservice nor destinationrule (in `tutorial` namespace) `kubectl get virtualservice` `kubectl get destinationrule` 
if so run:
 
[source, bash,subs="+macros,+attributes"]
----
./scripts/clean.sh tutorial{namespace-suffix}
----
 
 
Make sure you are in the main directory of "istio-tutorial"
 
[source,bash,subs="+macros,+attributes"]
----
kubectl create -f link:{github-repo}/{istiofiles-dir}/destination-rule-recommendation-v1-v2.yml[istiofiles/destination-rule-recommendation-v1-v2.yml] -n tutorial{namespace-suffix}
kubectl create -f link:{github-repo}/{istiofiles-dir}/virtual-service-recommendation-v1-mirror-v2.yml[istiofiles/virtual-service-recommendation-v1-mirror-v2.yml] -n tutorial{namespace-suffix}
 
curl istio-ingressgateway-istio-system.{appdomain}/{path}
----
 
Check the logs of recommendation-v2
 
[source,bash,subs="+macros,+attributes"]
----
oc logs -f `oc get pods -n tutorial{namespace-suffix}|grep recommendation-v2|awk '{ print $1 }'` -c recommendation -n tutorial{namespace-suffix}
or
kubectl logs -f `oc get pods -n tutorial{namespace-suffix}|grep recommendation-v2|awk '{ print $1 }'` -c recommendation -n tutorial{namespace-suffix}
----
 
=== Clean up
 
[source,bash,subs="+macros,+attributes"]
----
kubectl delete -f istiofiles/destination-rule-recommendation-v1-v2.yml -n tutorial{namespace-suffix}
kubectl delete -f istiofiles/virtual-service-recommendation-v1-mirror-v2.yml -n tutorial{namespace-suffix}
----
 
or you can run:
 
[source, bash,subs="+macros,+attributes"]
----
./scripts/clean.sh tutorial{namespace-suffix}
----
 
 
[#loadbalancer]
== Load Balancer
 
By default, you will see "round-robin" style load-balancing, but you can change it up, with the RANDOM option being fairly visible to the naked eye.
 
Add another v2 pod to the mix
 
[source,bash,subs="+macros,+attributes"]
----
oc scale deployment recommendation-v2 --replicas=2 -n tutorial{namespace-suffix}
or
kubectl scale deployment recommendation-v2 --replicas=2 -n tutorial{namespace-suffix}
----
 
Wait a bit (oc get pods -w to watch)
and curl the customer endpoint many times
 
[source,bash,subs="+macros,+attributes"]
----
curl istio-ingressgateway-istio-system.{appdomain}/{path}
----
 
Add a 3rd v2 pod to the mix
 
[source,bash,subs="+macros,+attributes"]
----
$ oc scale deployment recommendation-v2 --replicas=3 -n tutorial{namespace-suffix}
$ oc get pods -n tutorial{namespace-suffix}
 
or 
 
$ kubectl scale deployment recommendation-v2 --replicas=3 -n tutorial{namespace-suffix}
$ kubectl get pods -n tutorial{namespace-suffix}
 
 
NAME                                  READY     STATUS    RESTARTS   AGE
customer-1755156816-cjd2z             2/2       Running   0          1h
preference-3336288630-2cc6f          2/2       Running   0          1h
recommendation-v1-3719512284-bn42p   2/2       Running   0          59m
recommendation-v2-2815683430-97nnf   2/2       Running   0          43m
recommendation-v2-2815683430-d49n6   2/2       Running   0          51m
recommendation-v2-2815683430-tptf2   2/2       Running   0          33m
----
 
Wait for those 2/2 (two containers in each pod) and then poll the customer endpoint:
 
[source, bash,subs="+macros,+attributes"]
----
./scripts/run.sh http://customer-tutorial{namespace-suffix}.{appdomain}
----
 
The results should follow a fairly normal round-robin distribution pattern
 
[source,bash,subs="+macros,+attributes"]
----
customer => preference => recommendation v1 from '99634814-d2z2t': 1145
customer => preference => recommendation v2 from '2819441432-525lh': 1
customer => preference => recommendation v2 from '2819441432-rg45q': 2
customer => preference => recommendation v2 from '2819441432-bs5ck': 181
customer => preference => recommendation v1 from '99634814-d2z2t': 1146
customer => preference => recommendation v2 from '2819441432-rg45q': 3
customer => preference => recommendation v2 from '2819441432-rg45q': 4
customer => preference => recommendation v2 from '2819441432-bs5ck': 182
----
 
Now, add the Random LB DestinationPolicy
 
[source,bash,subs="+macros,+attributes"]
----
kubectl create -f link:{github-repo}/{istiofiles-dir}/destination-rule-recommendation_lb_policy_app.yml[istiofiles/destination-rule-recommendation_lb_policy_app.yml] -n tutorial{namespace-suffix}
----
 
And you should see a different pattern of which pod is being selected
 
[source,bash,subs="+macros,+attributes"]
----
customer => preference => recommendation v2 from '2819441432-rg45q': 10
customer => preference => recommendation v2 from '2819441432-525lh': 3
customer => preference => recommendation v2 from '2819441432-rg45q': 11
customer => preference => recommendation v1 from '99634814-d2z2t': 1153
customer => preference => recommendation v1 from '99634814-d2z2t': 1154
customer => preference => recommendation v1 from '99634814-d2z2t': 1155
customer => preference => recommendation v2 from '2819441432-rg45q': 12
customer => preference => recommendation v2 from '2819441432-525lh': 4
customer => preference => recommendation v2 from '2819441432-525lh': 5
customer => preference => recommendation v2 from '2819441432-rg45q': 13
customer => preference => recommendation v2 from '2819441432-rg45q': 14
----
 
=== Clean up
 
[source,bash,subs="+macros,+attributes"]
----
kubectl delete -f istiofiles/destination-rule-recommendation_lb_policy_app.yml -n tutorial{namespace-suffix}
 
oc scale deployment recommendation-v2 --replicas=1 -n tutorial{namespace-suffix}
or
kubectl scale deployment recommendation-v2 --replicas=1 -n tutorial{namespace-suffix}
----