DestinationRule을 생성하여 서비스 버전별로 트래픽을 분리하는 방법을 실습한다.
git clone https://github.com/istio/istio.git
cd istio/samples/helloworld
# v1 배포
kubectl apply -f helloworld-v1.yaml
# v2 배포
kubectl apply -f helloworld-v2.yaml
# 확인
kubectl get pods -l app=helloworld
v1과 v2 파드가 모두 떠 있는 것을 확인한다.
destination-rule-helloworld.yaml 파일 생성:
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: helloworld
spec:
host: helloworld
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
적용:
kubectl apply -f destination-rule-helloworld.yaml
virtual-service-helloworld.yaml 파일 생성:
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: helloworld
spec:
hosts:
- helloworld
http:
- route:
- destination:
host: helloworld
subset: v1
weight: 50
- destination:
host: helloworld
subset: v2
weight: 50
적용:
kubectl apply -f virtual-service-helloworld.yaml
테스트용 파드에서 helloworld 서비스 호출:
kubectl run -it --rm --restart=Never test-pod --image=curlimages/curl -- curl helloworld:5000/hello
v1과 v2가 번갈아 응답하는지 확인한다.