Advanced Router Rules - TheOpenCloudEngine/uEngine-cloud GitHub Wiki
What is your 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>
.
istioctl create -f istiofiles/destination-rule-recommendation-v1-v2.yml
istioctl create -f istiofiles/virtual-service-recommendation-v1.yml
istioctl replace -f istiofiles/virtual-service-safari-recommendation-v2.yml
istioctl get virtualservice -n tutorial
๊ทธ๋ฐํ์ Safari ๋ธ๋ผ์ฐ์ ๋ก ์ ์ํฉ๋๋ค.(ํน์ Firefox ๋ธ๋ผ์ฐ์ ์ฉ ์ค์ ์ผ๋ก ๋ํ๋ก์ด ํํ, ์์ ๋ฅผ ํ ์คํธ ํฉ๋๋ค.
ํน์, curl -A ์ปค๋งจ๋๋ฅผ ํตํ์ฌ user-agent ๋ฌธ์์ด์ ์ ๋ฌํ ์ ์์ต๋๋ค.
curl -A Safari <service url>
curl -A Firefox <service url>
์๋์ฐ ๋ฐฐํฌ๋ฅผ ํ ์คํธํ๊ธฐ ์ํด์๋ recommendation ๋ฒ์ ์ด 2๊ฐ ์ด์์์ด์ผ ํฉ๋๋ค. ์ค์ ํธ๋ํฝ์ ๊ฒฐ๊ณผ๋ ๋ชจ๋ v1๊ฒ์ ์ ์ ๋ก ๋ณด๋ด๋ฉด์ v2
istioctl create -f istiofiles/destination-rule-recommendation-v1-v2.yml -n tutorial
istioctl create -f istiofiles/virtual-service-recommendation-v1-mirror-v2.yml -n tutorial
curl <service url>
recommendation-v2 ์ ๋ก๊ทธ ํ์ธํ๊ธฐ
kubectl logs -f `oc get pods|grep recommendation-v2|awk '{ print $1 }'` -c recommendation
Important
|
The Access Control rules take some time to be applied and reflected. Be patient here! |
Weโll create a whitelist on the preference service to only allow requests from the recommendation service, which will make the preference service invisible to the customer service. Requests from the customer service to the preference service will return a 404 Not Found HTTP error code.
istioctl create -f istiofiles/acl-whitelist.yml -n tutorial
curl customer-tutorial.$(minishift ip).nip.io
customer => 404 NOT_FOUND:preferencewhitelist.listchecker.tutorial:customer is not whitelisted
Weโll create a blacklist making the customer service blacklist to the preference service. Requests from the customer service to the preference service will return a 403 Forbidden HTTP error code.
istioctl create -f istiofiles/acl-blacklist.yml -n tutorial
curl customer-tutorial.$(minishift ip).nip.io
customer => 403 PERMISSION_DENIED:denycustomerhandler.denier.tutorial:Not allowed
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
oc scale deployment recommendation-v2 --replicas=2 -n tutorial
or
kubectl scale deployment recommendation-v2 --replicas=2 -n tutorial
Wait a bit (oc get pods -w to watch) and curl the customer endpoint many times
curl customer-tutorial.$(minishift ip).nip.io
Add a 3rd v2 pod to the mix
$ oc scale deployment recommendation-v2 --replicas=3 -n tutorial
$ oc get pods -n tutorial
or
$ kubectl scale deployment recommendation-v2 --replicas=3 -n tutorial
$ kubectl get pods -n tutorial
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:
./scripts/run.sh
The results should follow a fairly normal round-robin distribution pattern
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
istioctl create -f istiofiles/destination-rule-recommendation_lb_policy_app.yml -n tutorial
And you should see a different pattern of which pod is being selected
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
istioctl delete -f istiofiles/destination-rule-recommendation_lb_policy_app.yml -n tutorial
oc scale deployment recommendation-v2 --replicas=1 -n tutorial
or
kubectl scale deployment recommendation-v2 --replicas=1 -n tutorial
Important
|
The Rate Limiting rules take some time to be applied and reflected. Be patient here! |
Here we will limit the number of concurrent requests into recommendation v2
Now apply the rate limit handler
istioctl create -f istiofiles/recommendation_rate_limit_handler.yml
Now setup the requestcount quota
istioctl create -f istiofiles/rate_limit_rule.yml
Throw some requests at customer:
./scripts/run.sh
You should see some 429 errors:
customer => preference => recommendation v2 from '2819441432-f4ls5': 108
customer => preference => recommendation v1 from '99634814-d2z2t': 1932
customer => preference => recommendation v2 from '2819441432-f4ls5': 109
customer => preference => recommendation v1 from '99634814-d2z2t': 1933
customer => 503 preference => 429 RESOURCE_EXHAUSTED:Quota is exhausted for: RequestCount
customer => preference => recommendation v1 from '99634814-d2z2t': 1934
customer => preference => recommendation v2 from '2819441432-f4ls5': 110
customer => preference => recommendation v1 from '99634814-d2z2t': 1935
customer => 503 preference => 429 RESOURCE_EXHAUSTED:Quota is exhausted for: RequestCount
customer => preference => recommendation v1 from '99634814-d2z2t': 1936
customer => preference => recommendation v2 from '2819441432-f4ls5': 111
customer => preference => recommendation v1 from '99634814-d2z2t': 1937
customer => 503 preference => 429 RESOURCE_EXHAUSTED:Quota is exhausted for: RequestCount
customer => preference => recommendation v1 from '99634814-d2z2t': 1938
customer => preference => recommendation v2 from '2819441432-f4ls5': 112
Clean up
istioctl delete -f istiofiles/rate_limit_rule.yml
istioctl delete -f istiofiles/recommendation_rate_limit_handler.yml
or you can run:
./scripts/clean.sh