Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Simple Router Rules

kimsanghoon1 edited this page Jan 16, 2019 · 1 revision

기초적인 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

Clone this wiki locally

Morty Proxy This is a proxified and sanitized view of the page, visit original site.