시작하기 - NGINX Ingress
이 가이드는 Argo Rollouts이 트래픽 조정(traffic shaping)을 위해 NGINX Ingress Controller와 어떻게 통합되는지 다룹니다. 이 가이드는 기본 시작하기 가이드의 개념을 바탕으로 합니다.
출처: Argo Rollouts 문서
본문
요구 사항 (Requirements)
- NGINX ingress controller가 설치된 Kubernetes 클러스터
팁 nginx와 함께 로컬 minikube 환경을 설정하는 방법은 NGINX 환경 설정 가이드를 참조하세요.
1. Rollout, Services, 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
- 두 개의 Service (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
롤아웃 컨트롤러가 생성한 두 번째 ingress, rollouts-demo-rollouts-demo-stable-canary도 확인할 수 있어야 합니다. 이 ingress는 "canary ingress"로, nginx.stableIngress 아래 참조된 사용자 관리 Ingress의 복제본입니다. nginx ingress controller가 카나리 트래픽 분할을 달성하는 데 사용합니다. 생성된 ingress의 이름은 <ROLLOUT-NAME>-<INGRESS-NAME>-canary 형식으로 만들어집니다. 두 번째 Ingress에 대한 자세한 내용은 다음 섹션에서 다룹니다.
kubectl argo rollouts get rollout rollouts-demo
![IMAGE] Rollout Nginx
2. 업데이트 수행하기
이미지를 변경하여 rollout을 업데이트하고, paused 상태에 도달할 때까지 기다립니다.
kubectl argo rollouts set image rollouts-demo rollouts-demo=argoproj/rollouts-demo:yellow
kubectl argo rollouts get rollout rollouts-demo
![IMAGE] Rollout Nginx Paused
이 시점에서 Rollout의 canary 버전과 stable 버전이 모두 실행 중이며, 트래픽의 5%가 canary로 전달됩니다. 한 가지 주목할 점은, 단 두 개의 pod만 실행 중임에도 롤아웃이 5% canary 가중치를 달성할 수 있다는 것입니다. 이는 트래픽 분할이 (기본 가이드의 가중치 replica 수와 kube-proxy 대신) ingress controller에서 발생하기 때문에 가능합니다.
롤아웃 컨트롤러가 생성한 Ingress 복사본을 검사하면, 원래 ingress에 비해 다음과 같은 변경 사항이 있음을 알 수 있습니다:
- NGINX 특유의 카나리 어노테이션 2개가 어노테이션에 추가됩니다.
- Ingress 규칙에 백엔드를 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이 단계를 진행함에 따라, canary-weight 어노테이션은 현재 단계의 setWeight와 일치하도록 조정됩니다. NGINX ingress controller는 원래 Ingress, canary Ingress, canary-weight 어노테이션을 검사하여 두 Ingress 사이에 트래픽을 어떤 비율로 분할할지 결정합니다.
더 알아보기 (Learn more)
- Blue-Green 배포 전략 — 다른 주요 배포 전략
- ALB 트래픽 관리 — AWS ALB와의 통합
- SMI 트래픽 관리 — 서비스 메시 통합