AWS Load Balancer Controller (ALB)와 트래픽 관리
Argo Rollouts이 AWS Load Balancer Controller(구 AWS ALB Ingress Controller)와 통합하여 Ingress 오브젝트를 통해 트래픽을 관리하는 방법을 알아봅니다. ALB의 가중치 기반 target group을 활용해 카나리/스테이블 서비스 간 트래픽을 분할합니다.
출처: Argo Rollouts 문서
본문
요구 사항 (Requirements)
- AWS Load Balancer Controller v1.1.5 이상
개요 (Overview)
AWS Load Balancer Controller(구 AWS ALB Ingress Controller)는 Ingress 오브젝트를 통해 트래픽 관리를 활성화합니다. 하나 이상의 Kubernetes 서비스로 트래픽을 라우팅하도록 AWS Application Load Balancer (ALB)를 구성합니다. ALB는 가중치가 적용된 target group을 통해 고급 트래픽 분할 기능을 제공합니다. AWS Load Balancer Controller는 Ingress 오브젝트의 어노테이션을 통해 "actions"을 구성하는 방식으로 이 기능을 지원합니다.
동작 방식 (How it works)
ALB는 Actions을 포함하는 Listeners와 Rules를 사용하여 구성됩니다. Listeners는 클라이언트 트래픽이 수신되는 방식을 정의하고, Rules는 다양한 Actions를 사용하여 이 요청을 처리하는 방법을 정의합니다. Action의 한 유형은 사용자가 여러 TargetGroup(각각 Kubernetes 서비스로 정의됨)으로 트래픽을 전달할 수 있게 합니다. ALB 개념에 대해 더 자세히 알아보려면 여기를 참조하세요.
AWS Load Balancer Controller가 관리하는 Ingress는 어노테이션과 spec을 통해 ALB의 Listener와 Rules를 제어합니다. 여러 target group(예: 서로 다른 Kubernetes 서비스) 간에 트래픽을 분할하기 위해, AWS Load Balancer Controller는 특정 action 어노테이션인 alb.ingress.kubernetes.io/actions.<service-name>을 사용합니다. 업데이트 동안 Rollout은 원하는 트래픽 가중치에 따라 이 어노테이션을 자동으로 주입하고 업데이트합니다.
사용법 (Usage)
Rollout이 ALB 통합을 사용하고 업데이트 중에 canary와 stable 서비스 간 트래픽을 분할하도록 구성하려면, Rollout을 다음 필드로 구성해야 합니다:
apiVersion: argoproj.io/v1alpha1
kind: Rollout
spec:
strategy:
canary:
# canaryService and stableService are references to Services which the Rollout will modify
# to target the canary ReplicaSet and stable ReplicaSet respectively (required).
canaryService: canary-service
stableService: stable-service
trafficRouting:
alb:
# The referenced ingress will be injected with a custom action annotation, directing
# the AWS Load Balancer Controller to split traffic between the canary and stable
# Service, according to the desired traffic weight (required).
ingress: ingress
# If you want to control multiple ingress resources you can use the ingresses field, if ingresses is specified
# the ingress field will need to be omitted.
ingresses:
- ingress-1
- ingress-2
# Reference to a Service that the Ingress must target in one of the rules (optional).
# If omitted, uses canary.stableService.
rootService: root-service
# Service port is the port which the Service listens on (required).
servicePort: 443
참조된 Ingress는 Rollout 서비스와 일치하는 ingress 규칙으로 배포되어야 합니다:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
annotations:
kubernetes.io/ingress.class: alb
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
# serviceName must match either: canary.trafficRouting.alb.rootService (if specified),
# or canary.stableService (if rootService is omitted)
name: root-service
# servicePort must be the value: use-annotation
# This instructs AWS Load Balancer Controller to look to annotations on how to direct traffic
port:
name: use-annotation
업데이트 동안 롤아웃 컨트롤러는 AWS Load Balancer Controller가 이해하는 JSON 페이로드를 포함한 alb.ingress.kubernetes.io/actions.<SERVICE-NAME> 어노테이션을 주입하여, 현재 카나리 가중치에 따라 canaryService와 stableService 간에 트래픽을 분할하도록 지시합니다. 다음은 롤아웃이 canary-service와 stable-service 간에 각각 10과 90의 트래픽 가중치로 트래픽을 분할하는 사용자 지정 action 어노테이션을 주입한 후의 예시 Ingress입니다:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/actions.root-service: |
{
"Type":"forward",
"ForwardConfig":{
"TargetGroups":[
{
"Weight":10,
"ServiceName":"canary-service",
"ServicePort":"80"
},
{
"Weight":90,
"ServiceName":"stable-service",
"ServicePort":"80"
}
]
}
}
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: root-service
port:
# Instructs AWS Load Balancer Controller to look to annotations on how to direct traffic
name: use-annotation
참고
Argo rollouts은 부가적으로 Ingress에 rollouts.argoproj.io/managed-alb-actions 어노테이션을 회계(bookkeeping) 목적으로 주입합니다. 이 어노테이션은 Rollout 오브젝트가 어떤 actions을 관리하고 있는지 나타냅니다 (여러 Rollout이 하나의 Ingress를 참조할 수 있기 때문입니다). 롤아웃이 삭제되면, 롤아웃 컨트롤러는 이 어노테이션을 보고 해당 action이 더 이상 관리되지 않음을 이해하고, 트래픽이 100 가중치로 stable 서비스만 가리키도록 재설정합니다.
rootService
기본적으로 롤아웃은 spec.strategy.canary.stableService 아래 지정된 service/action 이름을 사용하여 alb.ingress.kubernetes.io/actions.<SERVICE-NAME> 어노테이션을 주입합니다. 그러나 stableService와 다른 명시적 service/action 이름을 지정하는 것이 바람직할 수 있습니다. 예를 들어, 한 가지 패턴은 canary, stable, root 서비스에 각각 도달하기 위해 서로 다른 세 개의 규칙을 포함하는 단일 Ingress를 사용하는 것입니다(예: 테스트 목적). 이 경우 stable 대신 service/action 이름으로 "root" 서비스를 지정하고 싶을 수 있습니다. 그러려면 alb spec 아래 rootService에 서비스를 참조하세요:
apiVersion: argoproj.io/v1alpha1
kind: Rollout
spec:
strategy:
canary:
canaryService: guestbook-canary
stableService: guestbook-stable
trafficRouting:
alb:
rootService: guestbook-root
고정 세션 (Sticky session)
적어도 두 개의 target group(canary와 stable)이 사용되므로, target group 고정(stickiness)에는 추가 구성이 필요합니다. 고정 세션은 다음을 통해 target group에서 활성화되어야 합니다:
apiVersion: argoproj.io/v1alpha1
kind: Rollout
spec:
strategy:
canary:
trafficRouting:
alb:
stickinessConfig:
enabled: true
durationSeconds: 3600
더 자세한 정보는 AWS ALB API에서 찾을 수 있습니다.
AWS TargetGroup 검증을 통한 제로 다운타임 업데이트
Argo Rollouts에는 AWS LoadBalancer controller와 함께 사용할 때 제로 다운타임 업데이트를 보장하기 위한 두 가지 기능이 있습니다: TargetGroup IP 검증과 TargetGroup weight 검증. 두 기능 모두 Rollout 컨트롤러가 Ingress 오브젝트에 대한 변경이 기본 AWS TargetGroup에 반영되었는지 확인하기 위해 AWS에 추가 안전 검사를 수행하는 것과 관련됩니다.
TargetGroup IP 검증
참고 Target Group IP 검증은 Argo Rollouts v1.1부터 사용 가능합니다.
AWS LoadBalancer controller는 두 가지 모드 중 하나로 실행될 수 있습니다:
- Instance 모드
- IP 모드
TargetGroup IP 검증은 AWS LoadBalancer controller가 IP 모드일 때만 적용됩니다. AWS LoadBalancer controller를 IP 모드로 사용할 때(예: AWS CNI 사용), ALB LoadBalancer는 K8s 노드 인스턴스가 아닌 개별 Pod IP를 대상으로 합니다. Pod IP를 대상으로 하면 업데이트 중 다운타임 위험이 증가합니다. 기본 AWS TargetGroup 뒤의 Pod IP가 pod의 실제 가용성 및 상태와 더 쉽게 오래될 수 있기 때문이며, TargetGroup이 이미 스케일다운된 pod를 가리키면 HTTP 502 오류가 발생합니다. 이 위험을 완화하기 위해 AWS는 AWS LoadBalancer를 IP 모드로 실행할 때 pod readiness gate 주입을 사용할 것을 권장합니다. Readiness gate를 사용하면 AWS LoadBalancer controller가 새로 생성된 Pod를 "ready"로 표시하기 전에 TargetGroup이 정확한지 검증할 수 있어, 이전 ReplicaSet의 조기 스케일다운을 방지합니다.
Pod readiness gate 주입은 mutating webhook을 사용하며, pod 생성 시 다음 조건에 따라 readiness gate 주입을 결정합니다:
- 같은 네임스페이스에 pod 레이블과 일치하는 서비스가 존재함
- 일치하는 서비스를 참조하는 target group 바인딩이 적어도 하나 존재함
다르게 말하면, AWS LoadBalancer controller는 pod가 생성 시점에 ALB Ingress에서 "도달 가능(reachable)"한 경우에만 pod에 readiness gate를 주입합니다. (ALB) Ingress가 pod 레이블과 일치하는 Service를 참조하면 pod는 도달 가능한 것으로 간주됩니다. 다른 모든 Pod는 무시됩니다. 이러한 pod readiness gate 주입 방식의 한 가지 과제는, Service selector 레이블(spec.selector)을 수정해도 AWS LoadBalancer controller가 readiness gate를 주입할 수 없다는 것입니다. 그때는 이미 pod가 생성되었기 때문입니다 (readiness gate는 불변입니다). 이는 Argo Rollouts에 관련된 ALB Service뿐 아니라 모든 ALB Service의 Service selector를 변경할 때 발생하는 문제입니다.
Argo Rollout의 블루-그린 전략이 승격 동안 activeService selector를 새 ReplicaSet 레이블로 수정하는 방식으로 동작하기 때문에, spec.strategy.blueGreen.activeService에 대한 readiness gate 주입에 실패하는 문제가 발생합니다. 이는 V1에서 V2로 업데이트하는 동안 다음 문제 시나리오에서 다운타임이 발생할 가능성이 있음을 의미합니다:
- 업데이트가 트리거되고 V2 ReplicaSet 스택이 스케일업됨
- V2 ReplicaSet pod가 완전히 준비되고 승격 준비가 됨
- Rollout이 active 서비스의 레이블 selector를 V2 스택을 가리키도록 업데이트하여 V2를 승격함 (V1에서)
- 알 수 없는 문제(예: AWS load balancer controller 다운타임, AWS rate limiting)로 인해 V2 Pod IP의 TargetGroup 등록이 발생하지 않거나 지연됨
- V1 ReplicaSet이 스케일다운되어 업데이트가 완료됨
5단계 이후, V1 ReplicaSet이 스케일다운되면, 오래된 TargetGroup은 더 이상 존재하지 않는 V1 Pod IP를 계속 가리켜 다운타임을 유발합니다. 제로 다운타임 업데이트를 허용하기 위해, Argo Rollouts은 업데이트 중 추가 안전 조치로 TargetGroup IP 검증을 수행할 수 있습니다. 이 기능이 활성화되면, 서비스 selector 수정이 이루어질 때마다 Rollout 컨트롤러는 TargetGroup이 bluegreen.activeService의 새 Pod IP를 정확하게 대상으로 하는지 검증할 수 있을 때까지 업데이트 진행을 차단합니다. 검증은 AWS API를 쿼리하여 기본 TargetGroup을 설명하고, 등록된 IP를 순회하며, activeService Endpoints 목록의 모든 Pod IP가 TargetGroup에 등록되었는지 확인함으로써 이루어집니다. postPromotionAnalysis를 실행하거나 이전 ReplicaSet을 스케일다운하기 전에 검증이 성공해야 합니다.
카나리 전략에서도 유사하게, canary.stableService selector 레이블을 새 ReplicaSet을 가리키도록 업데이트한 후, TargetGroup IP 검증 기능을 통해 컨트롤러는 stableService TargetGroup 뒤의 Pod IP가 정확한지 검증할 때까지 이전 ReplicaSet의 스케일다운을 차단할 수 있습니다.
TargetGroup Weight 검증
참고 TargetGroup weight 검증은 Argo Rollouts v1.0부터 사용 가능합니다.
TargetGroup weight 검증은 TargetGroup IP 검증과 유사한 문제를 다루지만, 서비스의 Pod IP가 TargetGroup에 정확히 반영되는지 검증하는 대신, 컨트롤러는 ingress 어노테이션에 설정된 트래픽 가중치가 정확한지 검증합니다. Weight 검증은 IP 모드 또는 Instance 모드로 실행되는 AWS LoadBalancer controllers에 적용됩니다. Argo Rollouts이 Ingress 어노테이션을 업데이트하여 카나리 가중치를 조정한 후, 다음 단계로 진행합니다. 그러나 외부 요인(예: AWS rate limiting, AWS load balancer controller 다운타임)으로 인해 Ingress에 가해진 가중치 수정이 기본 TargetGroup에 반영되지 않았을 수 있습니다. 이는 컨트롤러가 이전 stable 스택을 스케일다운해도 안전하다고 믿는 동안 실제로는 오래된 TargetGroup이 여전히 그것을 가리킬 수 있기 때문에 잠재적으로 위험합니다.
TargetGroup weight 검증 기능을 사용하면, 롤아웃 컨트롤러가 setWeight 카나리 단계 후 카나리 가중치를 추가로 검증합니다. AWS LoadBalancer API를 직접 쿼리하여 Rules, Actions, TargetGroups가 Ingress 어노테이션의 의도를 반영하는지 확인함으로써 이를 수행합니다.
사용법 (Usage)
AWS target group 검증을 활성화하려면 rollout-controller 플래그에 --aws-verify-target-group 플래그를 추가하세요:
apiVersion: apps/v1
kind: Deployment
metadata:
name: argo-rollouts
spec:
template:
spec:
containers:
- name: argo-rollouts
args: [--aws-verify-target-group]
# NOTE: in v1.0, the --alb-verify-weight flag should be used instead
참고
AWS 통합(including TargetGroup 검증)을 활성화하려면 --aws-region 플래그가 필수입니다. Argo Rollouts 컨트롤러에 올바른 AWS 리전이 지정되지 않았거나, AWS ALB를 검증할 권한이 없으면, 승격 프로세스가 실패합니다. 컨트롤러에 필요한 AWS API 권한이 부여되고 리전이 올바르게 구성되었는지 확인하세요.
이 기능이 작동하려면 argo-rollouts 배포에 Elastic Load Balancing API 아래의 다음 AWS API 권한이 필요합니다:
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"elasticloadbalancing:DescribeTargetGroups",
"elasticloadbalancing:DescribeLoadBalancers",
"elasticloadbalancing:DescribeListeners",
"elasticloadbalancing:DescribeRules",
"elasticloadbalancing:DescribeTags",
"elasticloadbalancing:DescribeTargetHealth"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
argo-rollouts pod에 AWS 권한을 부여하는 방법은 다양하며, 이는 클러스터의 AWS 환경에 크게 의존하고 이 문서의 범위를 벗어납니다. 몇 가지 솔루션은 다음과 같습니다:
- AWS access and secret keys
- kiam
- kube2iam
- EKS ServiceAccount IAM Roles
Ping-Pong 기능을 통한 제로 다운타임 업데이트
위에서 설명한 대로, AWS는 제로 다운타임 업데이트를 달성하기 위해 AWS LoadBalancer를 IP 모드로 실행할 때 pod readiness gate 주입을 사용할 것을 권장합니다. 그러나 이 접근 방식에는 과제가 있습니다: Service selector 레이블(spec.selector) 수정은 AWS LoadBalancer controller가 readiness gate를 변경하는 것을 방해합니다. Ping-Pong 기능은 이 과제를 해결하는 데 도움이 됩니다. 어떤 순간에든 하나의 서비스(예: ping)가 stable 서비스로, 다른 하나(예: pong)가 canary로 작동합니다. 승격 단계가 끝나면 트래픽의 100%가 "canary"(예: pong)로 전달됩니다. 그런 다음 Rollout은 ping과 pong 서비스의 역할을 교환하여 pong을 새 stable 서비스로 만듭니다. Rollout status 오브젝트는 status.canary.currentPingPong 필드를 통해 현재 어떤 서비스가 stable인지 추적합니다. 이 접근 방식은 서비스가 롤아웃 프로세스 전체에서 레이블을 유지하므로 pod readiness gate 주입을 사용할 수 있게 합니다.
중요 Ping-Pong 기능은 Argo Rollouts v1.2부터 사용 가능합니다.
예시 (Example)
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: example-rollout
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.15.4
ports:
- containerPort: 80
strategy:
canary:
pingPong: #Indicates that the ping-pong services enabled
pingService: ping-service
pongService: pong-service
trafficRouting:
alb:
ingress: alb-ingress
servicePort: 80
steps:
- setWeight: 20
- pause: {}
사용자 지정 어노테이션 접두사 (Custom annotations-prefix)
AWS Load Balancer Controller는 사용자가 컨트롤러의 --annotations-prefix 플래그(기본값 alb.ingress.kubernetes.io)를 사용하여 Ingress controller가 사용하는 어노테이션 접두사를 사용자 지정할 수 있게 합니다. AWS Load Balancer Controller가 다른 어노테이션 접두사를 사용하도록 사용자 지정된 경우, 클러스터의 aws load balancer controller가 이해하는 방식으로 Ingress 오브젝트에 어노테이션이 기록되도록 annotationPrefix 필드를 지정해야 합니다.
apiVersion: argoproj.io/v1alpha1
kind: Rollout
spec:
strategy:
canary:
trafficRouting:
alb:
annotationPrefix: custom.alb.ingress.kubernetes.io
사용자 지정 Ingress Class
기본적으로 Argo Rollout은 다음 어노테이션이 있는 Ingress에서 동작합니다:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: alb
또는 ingressClassName을 사용합니다:
apiVersion: networking.k8s.io/v1
kind: Ingress
spec:
ingressClassName: alb
다른 클래스 이름을 가진 Ingress에서 동작하도록 컨트롤러를 구성하려면, 컨트롤러 커맨드라인 인수에서 --alb-ingress-classes 플래그를 통해 다른 값을 지정할 수 있습니다. 참고로, Argo Rollouts 컨트롤러가 여러 값에서 동작해야 한다면 --alb-ingress-classes 플래그를 여러 번 지정할 수 있습니다. 이는 클러스터에 서로 다른 kubernetes.io/ingress.class 또는 spec.ingressClassName 값에서 동작하는 여러 Ingress controller가 있을 때 바람직할 수 있습니다. 컨트롤러가 kubernetes.io/ingress.class 어노테이션 또는 spec.ingressClassName이 없는 Ingress에서도 동작해야 한다면, 플래그를 빈 문자열로 지정할 수 있습니다 (예: --alb-ingress-classes '').
더 알아보기 (Learn more)
- SMI 트래픽 관리 — 서비스 메시 인터페이스 기반 트래픽 관리
- NGINX로 시작하기 — 인그레스 컨트롤러 통합
- Blue-Green 배포 전략 — 주요 배포 전략