Simple Router Rules - TheOpenCloudEngine/uEngine-cloud GitHub Wiki
ํ๋์ด์์ ๋ฒ์ ์ ์ํฉ์ ๋ฐ๋ผ ๋ฒ๊ฐ์๊ฐ๋ฉฐ ๋ผ์ฐํ ํ๋ Canary Deploy ์ ์๋๋ฆฌ์ค๋ฅผ ์ํด v2 recommendation ์๋น์ค๋ฅผ ๋ํ๋ก์ด ํฉ๋๋ค. ์ด๋ฅผ ์ํด์ ๋ค์๊ณผ ๊ฐ์ด ๊ธฐ์กด recommendation ์๋น์ค์ ์ฝ๋ ์ผ๋ถ๋ฅผ ์์ ํฉ๋๋ค:
Istio ์ ํธ๋ํฝ ์ปจํธ๋กค ๊ธฐ๋ฅ์ ํ์ธํ๊ธฐ ์ํ์ฌ `RecommendationVerticle.java` ๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ์์ ํ๊ณ ๋์ปค์ด๋ฏธ์ง๋ฅผ ๋น๋/๋ฐฐํฌํฉ๋๋ค.
private static final String RESPONSE_STRING_FORMAT = "recommendation v2 from '%s': %d\n";
์ด๋, "v2"๋ก ๋์ปค์ด๋ฏธ์ง๋ฅผ ๋น๋ํ ๋ ๋ฒ์ ์ ๋ช ์ํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค.
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
ํด๋น 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-tutorial ๋ฉ์ธ ๋๋ ํ ๋ฆฌ๋ก ์ด๋ํ ํ,
istioctl create -f istiofiles/destination-rule-recommendation-v1-v2.yml
istioctl create -f istiofiles/virtual-service-recommendation-v2.yml
curl <service url>
v2 ๋ง์ด ํ์๋๋ ๊ฒ์ ํ์ธ ํ ์ ์์ต๋๋ค.
Note: "create"๋ณด๋ค๋ "replace" ๋ฅผ ์ฌ์ฉํด์ผ ๊ธฐ์กด ์ค์ ์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
istioctl replace -f istiofiles/virtual-service-recommendation-v1.yml
istioctl get virtualservice
istioctl get virtualservice -o yaml
๊ทธ๋ฅ ๊ธฐ์กด ๋ฃฐ์ ์ ๊ฑฐํ๋ฉด, ๊ธฐ๋ณธ ๋ผ์ด๋-๋ก๋น ๋ฐฉ์์ผ๋ก ๋ค์ ์ ํ๋ฉ๋๋ค:
istioctl delete -f istiofiles/virtual-service-recommendation-v1.yml
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