버전 1번은 V1가 나오게 하고, 버전 2번은 V2가 나오게 만들었다.
일단 deploy를 두개, svc를 한개를 만들어두자
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: null
name: test
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-server-v1
namespace: test
labels:
app: hello
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: hello
version: v1
template:
metadata:
labels:
app: hello
version: v1
spec:
containers:
- image: ${자신 ecrd이미지}:v1
imagePullPolicy: IfNotPresent
name: hello-server-v1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-server-v2
labels:
app: hello
version: v2
spec:
replicas: 1
selector:
matchLabels:
app: hello
version: v2
template:
metadata:
labels:
app: hello
version: v2
spec:
containers:
- image: ${자신 이미지ecr위치}:v2
imagePullPolicy: IfNotPresent
name: hello-server-v2
---
apiVersion: v1
kind: Service
metadata:
name: svc-hello
namespace: test
labels:
app: hello
spec:
selector:
app: hello
ports:
- name: http
protocol: TCP
port: 5000
Destination룰을 생성한다
subnets:v1은 version: v1 라벨이 달린 pod로 갈것이고, subnets:v2는 version: v2 라벨이 달린 pod로 갈것이당.
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: dr-hello
namespace: test
spec:
host: svc-hello.test.svc.cluster.local
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
VirtualService를 이용해서 weight를 조절한다.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: vs-hello
namespace: test
spec:
hosts:
- svc-hello.test.svc.cluster.local
http:
- route:
- destination:
host: svc-hello.test.svc.cluster.local
subset: v1
weight: 100
- destination:
host: svc-hello.test.svc.cluster.local
subset: v2
weight: 0
pod에서 호출하면서 확인한다.
while true; do curl http://svc-hello.test.svc.cluster.local:5000; sleep 1; done
VirtualService를 이용해서 weight를 조절한다.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: vs-hello
namespace: test
spec:
hosts:
- svc-hello.test.svc.cluster.local
http:
- route:
- destination:
host: svc-hello.test.svc.cluster.local
subset: v1
weight: 60
- destination:
host: svc-hello.test.svc.cluster.local
subset: v2
weight: 40
VirtualService를 이용해서 weight를 조절한다.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: vs-hello
namespace: test
spec:
hosts:
- svc-hello.test.svc.cluster.local
http:
- route:
- destination:
host: svc-hello.test.svc.cluster.local
subset: v1
weight: 0
- destination:
host: svc-hello.test.svc.cluster.local
subset: v2
weight: 100
점점 이동하는 것을 볼수있음.
결과적으로 v2만 남게된다.
좋은 글 감사합니다.