시작하기 - NGINX Ingress
이 가이드는 Argo Rollouts가 트래픽 셰이핑을 위해 NGINX Ingress Controller와 어떻게 통합되는지 설명해요. 이 가이드는 기본 시작하기 가이드의 개념을 바탕으로 진행해요.
출처: 문서
본문
이 가이드는 Argo Rollouts가 트래픽 셰이핑을 위해 NGINX Ingress Controller와 어떻게 통합되는지 설명해요. 이 가이드는 기본 시작하기 가이드의 개념을 바탕으로 진행해요.
Requirements
- NGINX ingress controller가 설치된 Kubernetes 클러스터
Tip
nginx를 사용해 로컬 minikube 환경을 설정하는 방법은 environment setup guide for NGINX를 참고해요.
1. Deploy the Rollout, Services, and Ingress
NGINX Ingress가 트래픽 라우터로 사용될 때, Rollout canary 전략은 다음 필수 필드를 정의해야 해요:
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollouts-demo
spec:
strategy:
canary:
# Reference to a Service which the controller will update to point to the canary ReplicaSet
canaryService: rollouts-demo-canary
# Reference to a Service which the controller will update to point to the stable ReplicaSet
stableService: rollouts-demo-stable
trafficRouting:
nginx:
# Reference to an Ingress which has a rule pointing to the stable service (e.g. rollouts-demo-stable)
# This ingress will be cloned with a new name, in order to achieve NGINX traffic splitting.
stableIngress: rollouts-demo-stable
...
canary.trafficRouting.nginx.stableIngress에서 참조하는 Ingress에는 canary.stableService 아래에서 참조하는 Service를 백엔드로 가리키는 host 규칙이 있어야 해요. 예제에서 그 stable Service 이름은 rollouts-demo-stable이에요:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rollouts-demo-stable
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: rollouts-demo.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
# Reference to a Service name, also specified in the Rollout spec.strategy.canary.stableService field
name: rollouts-demo-stable
port:
number: 80
다음 명령을 실행해 배포해요:
-
Rollout 하나
-
두 개의 서비스 (stable과 canary)
-
Ingress 하나
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/docs/getting-started/nginx/rollout.yaml
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/docs/getting-started/nginx/services.yaml
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/docs/getting-started/nginx/ingress.yaml
매니페스트를 적용하고 나면 클러스터에서 다음과 같은 rollout, services, ingress 리소스를 볼 수 있어요:
$ kubectl get ro
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE
rollouts-demo 1 1 1 1
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
rollouts-demo-canary ClusterIP 10.96.6.241 <none> 80/TCP 33s
rollouts-demo-stable ClusterIP 10.102.229.83 <none> 80/TCP 33s
$ kubectl get ing
NAME CLASS HOSTS ADDRESS PORTS AGE
rollouts-demo-stable <none> rollouts-demo.local 192.168.64.2 80 36s
rollouts-demo-rollouts-demo-stable-canary <none> rollouts-demo.local 192.168.64.2 80 35s
또한 rollouts 컨트롤러가 만든 두 번째 ingress, rollouts-demo-rollouts-demo-stable-canary를 확인할 수 있어요. 이 ingress는 nginx.stableIngress 아래에서 참조하는 사용자 관리 Ingress의 복제본인 "canary ingress"예요. nginx ingress controller가 canary 트래픽 분할을 달성하는 데 사용되죠. 생성된 ingress의 이름은 <ROLLOUT-NAME>-<INGRESS-NAME>-canary 형식으로 만들어진답니다. 두 번째 Ingress에 대한 자세한 내용은 다음 섹션에서 다뤄요.
kubectl argo rollouts get rollout rollouts-demo
2. Perform an update
이미지를 변경해 rollout을 업데이트하고, paused 상태에 도달할 때까지 기다려요.
kubectl argo rollouts set image rollouts-demo rollouts-demo=argoproj/rollouts-demo:yellow
kubectl argo rollouts get rollout rollouts-demo
이 시점에서 Rollout의 canary와 stable 두 버전 모두 실행되고 있으며, 트래픽의 5%가 canary로 전달돼요. 주목할 점은 rollout이 두 개의 Pod만 실행하고 있는데도 5% canary 가중치를 달성한다는 거예요. 이는 트래픽 분할이 ingress controller에서 발생하기 때문이에요 (기본 가이드의 가중치 복제본 수와 kube-proxy 방식과 반대).
rollout 컨트롤러가 생성한 Ingress 복제본을 살펴보면 원래 ingress와 비교해 다음과 같은 변경 사항이 있음을 알 수 있어요:
-
두 개의 추가 NGINX 특정 canary annotation이 annotations에 추가돼요.
-
Ingress rules에 백엔드를 canary 서비스로 가리키는 규칙이 추가돼요.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: rollouts-demo-rollouts-demo-stable-canary
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/canary: "true"
nginx.ingress.kubernetes.io/canary-weight: "5"
spec:
rules:
- host: rollouts-demo.local
http:
paths:
- backend:
serviceName: rollouts-demo-canary
servicePort: 80
Rollout이 steps를 진행하면서 canary-weight annotation이 steps의 현재 setWeight와 일치하도록 조정돼요. NGINX ingress controller는 원래 Ingress, canary Ingress, 그리고 canary-weight annotation을 검사해 두 Ingress 사이에서 트래픽의 몇 퍼센트를 분할할지 결정해요.