Nginx
Nginx Ingress Controller는 하나 이상의 Ingress 객체를 통해 트래픽 관리를 제공해서, 트래픽을 파드로 직접 라우팅하는 Nginx 배포를 구성해요. 각 Nginx Ingress에는 Nginx 배포의 동작을 수정하는 여러 annotation이 포함돼요. 애플리케이션의 서로 다른 버전 사이의 트래픽 관리를 위해, Nginx Ingress 컨트롤러는 특별한 annotation을 가진 두 번째 Ingress 객체(카나리아 Ingress라고 부름)를 도입해서 트래픽을 나누는 기능을 제공해요. 이 카나리아 annotation에 대한 자세한 내용은 공식 카나리아 annotation 문서를 참고하면 돼요. 카나리아 Ingress는 카나리아가 아닌 다른 nginx annotation은 무시하고, 대신 기본(primary) Ingress의 annotation 설정을 활용해요.
출처: 문서
본문
Nginx Ingress Controller는 하나 이상의 Ingress 객체를 통해 트래픽 관리를 제공해서, 트래픽을 파드로 직접 라우팅하는 Nginx 배포를 구성해요. 각 Nginx Ingress에는 Nginx 배포의 동작을 수정하는 여러 annotation이 포함돼요. 애플리케이션의 서로 다른 버전 사이의 트래픽 관리를 위해, Nginx Ingress 컨트롤러는 특별한 annotation을 가진 두 번째 Ingress 객체(카나리아 Ingress라고 부름)를 도입해서 트래픽을 나누는 기능을 제공해요. 이 카나리아 annotation에 대한 자세한 내용은 공식 카나리아 annotation 문서를 참고하면 돼요. 카나리아 Ingress는 카나리아가 아닌 다른 nginx annotation은 무시하고, 대신 기본(primary) Ingress의 annotation 설정을 활용해요.
Rollout 컨트롤러는 카나리아 Ingress에 다음 두 annotation을 항상 설정해요(설정한 값이나 기본 nginx.ingress.kubernetes.io 접두사를 사용해요).
canary: true- 이 Ingress가 카나리아 Ingress임을 나타내요canary-weight: <num>- 카나리아로 보낼 트래픽의 비율을 나타내요. 모든 트래픽이 안정 Service로 라우팅되면0으로 설정돼요
헤더나 쿠키 기반 라우팅 같은 기능을 활성화하기 위해 additionalIngressAnnotations 또는 canaryIngressAnnotations 필드로 카나리아 Ingress에 추가 annotation을 넣을 수 있어요. 전자는 공통적이고 주입 가능한 nginx annotation 접두사를 재사용할 수 있게 하고, 후자는 어떤 그룹이든 사용자 정의 전체 annotation을 정의할 수 있게 해요. 후자는 서드파티 메트릭 스크레이퍼나 다른 인프라 통합 같은 독립적인 메커니즘에 관련될 수 있죠.
Argo Rollouts과의 통합 (Integration with Argo Rollouts)
Nginx로 버전 사이의 트래픽을 나누려면 Rollout에 몇 가지 필수 필드가 있어야 해요. 아래는 그 필드가 있는 Rollout 예시예요.
apiVersion: argoproj.io/v1alpha1
kind: Rollout
spec:
...
strategy:
canary:
canaryService: canary-service # required
stableService: stable-service # required
trafficRouting:
nginx:
# Either stableIngress or stableIngresses must be configured, but not both.
stableIngress: primary-ingress
stableIngresses:
- primary-ingress
- secondary-ingress
- tertiary-ingress
annotationPrefix: customingress.nginx.ingress.kubernetes.io # optional
additionalIngressAnnotations: # optional
canary-by-header: X-Canary
canary-by-header-value: iwantsit
canaryIngressAnnotations: # optional
my-custom-annotation.mygroup.com/key: value
stable Ingress 필드는 Rollout과 같은 네임스페이스에 있는 Ingress에 대한 참조예요. Rollout은 기본 Ingress가 트래픽을 안정 Service로 라우팅할 것을 요구해요. Rollout은 Ingress에 Rollout의 stableService와 일치하는 backend가 있는지 확인해서 이 조건을 검사해요.
컨트롤러는 카나리아 annotation을 가진 두 번째 Ingress를 만들어 카나리아 Service로 트래픽을 라우팅해요. Rollout이 Canary 단계를 진행할수록 컨트롤러는 카나리아 Ingress의 카나리아 annotation을 업데이트해서 Rollout의 원하는 상태를 반영해, 두 버전 사이의 트래픽 분할을 가능하게 해요.
Nginx Ingress 컨트롤러는 Ingress 컨트롤러가 사용하는 annotation 접두사를 사용자가 설정할 수 있게 하므로, Rollouts는 선택적 annotationPrefix 필드를 지정할 수 있어요. 이 필드가 설정된 경우 카나리아 Ingress는 기본 nginx.ingress.kubernetes.io 대신 그 접두사를 사용해요.
Kubernetes 문서에 정의된 대로 서로 다른 그룹의 전체 annotation을 선언해야 한다면 canaryIngressAnnotations 필드를 사용할 수 있어요. 이 필드는 비슷한 key-value 구조를 받지만 접두사 주입을 수행하지 않아요. additionalIngressAnnotations와 충돌하면 canaryIngressAnnotations의 값이 우선한다는 점을 참고하세요.
서비스당 여러 NGINX ingress 컨트롤러와 Argo Rollouts 사용하기
v1.5부터 argo rollouts는 카나리아 배포가 있는 하나의 서비스를 가리키는 여러 Nginx ingress 컨트롤러를 지원해요. ingress 컨트롤러가 하나만 필요하다면 기존 키인 stableIngress를 사용하면 돼요. 여러 ingress 컨트롤러가 필요하다면(예: 내부 vs 외부 트래픽 분리) stableIngresses 키를 대신 사용해요. 이 키는 ingress 컨트롤러 이름인 문자열 값의 배열을 받아요. 카나리아 단계는 모든 ingress 컨트롤러에 동일하게 적용돼요.
사용자 지정 NGINX ingress 컨트롤러 이름과 Argo Rollouts 사용하기
기본적으로 Argo Rollouts 컨트롤러는 kubernetes.io/ingress.class annotation 또는 spec.ingressClassName이 nginx로 설정된 ingress에서만 동작해요. 사용자는 --nginx-ingress-classes 플래그를 지정해서 다른 class 이름의 Ingress에서 동작하도록 컨트롤러를 설정할 수 있어요. Argo Rollouts 컨트롤러가 여러 값에서 동작해야 한다면 --nginx-ingress-classes 플래그를 여러 번 나열하면 돼요. 이렇게 하면 서로 다른 class 값에서 동작하는 여러 Ingress 컨트롤러가 있는 클러스터의 문제를 해결할 수 있어요.
kubernetes.io/ingress.class annotation이나 spec.ingressClassName이 없는 모든 Ingress에서 컨트롤러가 동작하게 하려면 --nginx-ingress-classes ''를 추가하면 돼요.