Simple Router Rules - TheOpenCloudEngine/uEngine-cloud GitHub Wiki

๊ธฐ์ดˆ์ ์ธ Routing Rule ์ฒ˜๋ฆฌ

ํ•˜๋‚˜์ด์ƒ์˜ ๋ฒ„์ „์„ ์ƒํ™ฉ์— ๋”ฐ๋ผ ๋ฒˆ๊ฐˆ์•„๊ฐ€๋ฉฐ ๋ผ์šฐํŒ…ํ•˜๋Š” Canary Deploy ์˜ ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์œ„ํ•ด v2 recommendation ์„œ๋น„์Šค๋ฅผ ๋””ํ”Œ๋กœ์ด ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ธฐ์กด recommendation ์„œ๋น„์Šค์˜ ์ฝ”๋“œ ์ผ๋ถ€๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค:

recommendation:v2 ์˜ ์ƒ์„ฑ

Istio ์˜ ํŠธ๋ž˜ํ”ฝ ์ปจํŠธ๋กค ๊ธฐ๋Šฅ์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•˜์—ฌ `RecommendationVerticle.java` ๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•˜๊ณ  ๋„์ปค์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œ/๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.
private static final String RESPONSE_STRING_FORMAT = "recommendation v2 from '%s': %d\n";

์ด๋•Œ, "v2"๋กœ ๋„์ปค์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œํ•  ๋•Œ ๋ฒ„์ „์„ ๋ช…์‹œํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.

Docker build (if you have access to Docker daemon)

cd recommendation/java/vertx
mvn clean package

docker build -t gcr.io/uengine-istio-test/recommendation:v2 .

docker images | grep recommendation
recommendation                  v2                  c31e399a9628        5 seconds ago       438MB
recommendation                  v1                  f072978d9cf6        8 minutes ago      438MB

๊ทธ๋ฆฌ๊ณ  docker image v2 ์šฉ Deployment ์„ค์ •์ธ Deployment-v2.yml ์„ ๋””ํ”Œ๋กœ์ดํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.

kubectl apply -f <(istioctl kube-inject -f ../../kubernetes/Deployment-v2.yml)
kubectl get pods -w

๋ฒ„์ „ 2๊ฐ€ ๋””ํ”Œ๋กœ์ด ๋  ๋•Œ๋ฅผ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค.

ํ•ด๋‹น pod๊ฐ€ istio side car ์™€ ํ•จ๊ป˜ ๊ธฐ๋™๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•˜์—ฌ READY ์ปฌ๋Ÿผ์ด "2/2" ๋กœ ํ‘œ์‹œ๋˜๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค:

NAME                                  READY     STATUS    RESTARTS   AGE
customer-3600192384-fpljb             2/2       Running   0          17m
preference-243057078-8c5hz           2/2       Running   0          15m
recommendation-v1-60483540-9snd9     2/2       Running   0          12m
recommendation-v2-2815683430-vpx4p   2/2       Running   0         15s

๊ทธ๋Ÿฐํ›„์— customer ๋ฅผ ํ…Œ์ŠคํŠธํ•ฉ๋‹ˆ๋‹ค:

curl <service ip>

you likely see "customer => preference => recommendation v1 from '99634814-d2z2t': 3", where '99634814-d2z2t' is the pod running v1 and the 3 is basically the number of times you hit the endpoint.

curl <service ip>

you likely see "customer => preference => recommendation v2 from '2819441432-5v22s': 1" as by default you get round-robin load-balancing when there is more than one Pod behind a Service

Send several requests to see their responses:

./scripts/run.sh

๊ธฐ๋ณธ Kubernetes ์˜ ๋™์ž‘์€ ๋ผ์šด๋“œ-๋กœ๋นˆ ๋ฐฉ์‹์œผ๋กœ pod๋“ค์— ๋ฒˆ๊ฐˆ์•„๊ฐ€๋ฉฐ ์›Œํฌ๋กœ๋“œ๋ฅผ ๋ฐฐ๋ถ„ํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์— ์ถ”๊ฐ€์ ์œผ๋กœ recommendation-v2 deployment ์— ๋Œ€ํ•œ ์ธ์Šคํ„ด์Šค๋ฅผ ๋Š˜์—ฌ์ค๋‹ˆ๋‹ค.

kubectl scale --replicas=2 deployment/recommendation-v2

๋ผ์šด๋“œ๋กœ๋นˆ์ด๊ธฐ ๋•Œ๋ฌธ์—, v1 ์— ํ•œ๋ฒˆ, v2์— ๋‘๋ฒˆ์”ฉ ๋ฒˆ๊ฐˆ์•„๊ฐ€๋ฉฐ ๋ฐฐ๋ถ„๋ฉ๋‹ˆ๋‹ค.

customer => preference => recommendation v1 from '2819441432-qsp25': 29
customer => preference => recommendation v2 from '99634814-sf4cl': 37
customer => preference => recommendation v2 from '99634814-sf4cl': 38

Istio ๋ผ์šฐํŒ… ์„ค์ •์˜ ๋ณ€๊ฒฝ

๋ชจ๋“  ์œ ์ €๊ฐ€ recommendation v2๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก

istio-tutorial ๋ฉ”์ธ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™ํ•œ ํ›„,

istioctl create -f istiofiles/destination-rule-recommendation-v1-v2.yml
istioctl create -f istiofiles/virtual-service-recommendation-v2.yml

curl <service url>

v2 ๋งŒ์ด ํ‘œ์‹œ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ชจ๋“  ์œ ์ €๋ฅผ v1๋งŒ ์‚ฌ์šฉํ•˜๋„๋ก

Note: "create"๋ณด๋‹ค๋Š” "replace" ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ๊ธฐ์กด ์„ค์ •์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

istioctl replace -f istiofiles/virtual-service-recommendation-v1.yml

istioctl get virtualservice

istioctl get virtualservice -o yaml

๋ชจ๋“  ์œ ์กฐ๋ฅผ recommendation v1 ๊ณผ v2๋ฅผ ๋ฐฐ๋ถ„ํ•˜์—ฌ ๋ผ์šฐํŒ…

๊ทธ๋ƒฅ ๊ธฐ์กด ๋ฃฐ์„ ์ œ๊ฑฐํ•˜๋ฉด, ๊ธฐ๋ณธ ๋ผ์šด๋“œ-๋กœ๋นˆ ๋ฐฉ์‹์œผ๋กœ ๋‹ค์‹œ ์ „ํ™˜๋ฉ๋‹ˆ๋‹ค:

istioctl delete -f istiofiles/virtual-service-recommendation-v1.yml

Canary deployment: ํŠธ๋ž˜ํ”ฝ์„ v1๊ณผ v2๋กœ ๋ฐฐ๋ถ„ํ•˜๊ธฐ

Canary Deployment scenario: push v2 into the cluster but slowly send end-user traffic to it, if you continue to see success, continue shifting more traffic over time

$ kubectl get pods -l app=recommendation

NAME                                  READY     STATUS    RESTARTS   AGE
recommendation-v1-3719512284-7mlzw   2/2       Running   6          2h
recommendation-v2-2815683430-vn77w   2/2       Running   0          1h

Create the virtualservice that will send 90% of requests to v1 and 10% to v2

istioctl create -f istiofiles/virtual-service-recommendation-v1_and_v2.yml

and send in several requests:

./scripts/run.sh

In another terminal, change the mixture to be 75/25

istioctl replace -f istiofiles/virtual-service-recommendation-v1_and_v2_75_25.yml

Clean up

istioctl delete -f istiofiles/virtual-service-recommendation-v1_and_v2_75_25.yml
istioctl delete -f istiofiles/destination-rule-recommendation-v1-v2.yml

or you can run:

./scripts/clean.sh
โš ๏ธ **GitHub.com Fallback** โš ๏ธ