AWS Load Balancer Controller (ALB)
AWS Load Balancer Controller(이전의 AWS ALB Ingress Controller)는 Ingress 객체를 통해 트래픽 관리를 제공해요. 하나 이상의 Kubernetes service로 트래픽을 라우팅하도록 AWS Application Load Balancer (ALB)를 설정해요. ALB는 가중치 기반 target group을 통해 고급 트래픽 분할 기능을 제공해요.
출처: 문서
본문
[AWS Load Balancer Controller]
요구사항 (Requirements)
- AWS Load Balancer Controller v1.1.5 이상
개요 (Overview)
AWS Load Balancer Controller(이전의 AWS ALB Ingress Controller)는 Ingress 객체를 통해 트래픽 관리를 제공해요. 하나 이상의 Kubernetes service로 트래픽을 라우팅하도록 AWS Application Load Balancer (ALB)를 설정해요. ALB는 가중치 기반 target group을 통해 고급 트래픽 분할 기능을 제공해요. AWS Load Balancer Controller는 Ingress 객체의 annotation으로 "actions"를 설정해서 이 기능을 지원해요.
동작 방식 (How it works)
ALB는 Actions를 포함하는 Listeners와 Rules로 설정돼요. Listener는 클라이언트 트래픽이 어떻게 수신되는지 정의하고, Rules는 다양한 Actions를 사용해 이 요청들을 어떻게 처리할지 정의해요. 한 가지 Action 유형은 사용자가 여러 TargetGroup(각각 Kubernetes service로 정의됨)으로 트래픽을 전달하게 해줘요. ALB 개념에 대해 더 자세히 알아보려면 여기를 참고하세요.
AWS Load Balancer Controller가 관리하는 Ingress는 annotation과 specification을 통해 ALB의 Listener와 Rules를 제어해요. 여러 target group(예: 서로 다른 Kubernetes service) 사이에서 트래픽을 나누기 위해, AWS Load Balancer Controller는 특정 action annotation을 사용해요: alb.ingress.kubernetes.io/actions.<service-name>. 업데이트 중에 Rollout은 원하는 트래픽 weight에 따라 이 annotation을 자동으로 주입하고 업데이트해요.
사용법 (Usage)
ALB 통합을 사용하고 업데이트 중에 canary·stable service 사이의 트래픽을 나누도록 Rollout을 설정하려면, 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 service와 일치하는 ingress rule로 배포되어야 해요.
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
업데이트 중에 rollout 컨트롤러는 alb.ingress.kubernetes.io/actions.<SERVICE-NAME> annotation을 주입하는데, 여기에는 AWS Load Balancer Controller가 이해하는 JSON 페이로드가 담겨 있어요. 이 페이로드는 현재 카나리아 weight에 따라 canaryService와 stableService 사이의 트래픽을 나누도록 지시해요.
다음은 rollout이 canary-service와 stable-service 사이의 트래픽을 weight 10과 90으로 나누는 사용자 지정 action annotation을 주입한 후의 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
참고 (Note)
Argo rollouts은 추가로 rollouts.argoproj.io/managed-alb-actions annotation을 장부(bookkeeping) 목적으로 Ingress에 주입해요. 이 annotation은 어떤 actions가 Rollout 객체에 의해 관리되는지를 나타내요(여러 Rollout이 하나의 Ingress를 참조할 수 있기 때문). rollout이 삭제되면 rollout 컨트롤러는 이 annotation을 보고 이 action이 더 이상 관리되지 않는다는 걸 이해하고, 오직 안정 service만 100 weight로 가리키도록 리셋해요.
rootService
기본적으로 rollout은 spec.strategy.canary.stableService 아래에 지정된 service/action 이름을 사용해 alb.ingress.kubernetes.io/actions.<SERVICE-NAME> annotation을 주입해요. 하지만 stableService와 다른 명시적 service/action 이름을 지정하고 싶을 수도 있어요. 예를 들어, canary·stable·root service에 각각 도달하도록 세 개의 서로 다른 rule이 있는 단일 Ingress를 사용하는 패턴이 있어요(예: 테스트 목적). 이런 경우 stable 대신 "root" service를 service/action 이름으로 지정하고 싶을 수 있어요. 그러려면 alb specification 아래의 rootService 아래에 service를 참조하면 돼요.
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 검증으로 무중단 업데이트 (Zero-Downtime Updates with AWS TargetGroup Verification)
Argo Rollouts에는 AWS LoadBalancer controller와 함께 사용할 때 무중단 업데이트를 보장하는 두 가지 기능이 있어요. TargetGroup IP 검증과 TargetGroup weight 검증이에요. 두 기능 모두 Rollout 컨트롤러가 AWS에 추가 안전 검사를 수행해서, Ingress 객체에 가한 변경이 기반이 되는 AWS TargetGroup에 반영되는지 확인하는 방식이에요.
TargetGroup IP 검증 (TargetGroup IP Verification)
참고 (Note)
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가 파드의 실제 가용성·상태와 더 쉽게 뒤떨어질 수 있어서, TargetGroup이 이미 스케일다운된 파드를 가리키면 HTTP 502 오류가 생길 수 있기 때문이에요.
이 위험을 완화하기 위해 AWS는 IP 모드로 AWS LoadBalancer를 실행할 때 pod readiness gate 주입(pod readiness gate injection)을 사용할 것을 권장해요. Readiness gates는 AWS LoadBalancer controller가 새로 생성된 Pod를 "ready"로 표시하기 전에 TargetGroups가 정확한지 검증하게 해서, 이전 ReplicaSet의 조기 스케일다운을 방지해요.
Pod readiness gate 주입은 mutating webhook을 사용하는데, 파드가 생성될 때 다음 조건에 따라 readiness gates를 주입할지 결정해요.
- 같은 네임스페이스에 파드 라벨과 일치하는 service가 존재
- 일치하는 service를 참조하는 target group binding이 최소한 하나 존재
다른 말로 하면, AWS LoadBalancer controller는 파드가 "ALB Ingress에서 도달 가능한(reachable)" 경우에만 파드에 readiness gates를 주입해요. 파드는 (ALB) Ingress가 파드 라벨과 일치하는 Service를 참조하면 도달 가능한 것으로 간주돼요. 다른 모든 Pod는 무시해요.
이 방식의 pod readiness gate 주입의 한 가지 문제는, Service selector 라벨(spec.selector)의 변경이 AWS LoadBalancer controller가 readiness gates를 주입하게 하지 못한다는 거예요. 그 시점에는 파드가 이미 생성됐기 때문이에요(readiness gates는 변경 불가). Argo Rollouts에 관련된 service뿐 아니라 어떤 ALB Service든 Service selector를 바꿀 때 이 문제가 생긴다는 점에 주의하세요.
Argo Rollout의 blue-green 전략은 승격(promotion) 중에 activeService selector를 새 ReplicaSet 라벨로 수정하는 방식으로 동작하므로, spec.strategy.blueGreen.activeService의 readiness gates가 주입되지 못하는 문제가 발생해요. 즉, V1에서 V2로 업데이트하는 동안 다음 문제 시나리오에서 다운타임이 생길 가능성이 있어요.
- 업데이트가 트리거되고 V2 ReplicaSet 스택이 스케일업
- V2 ReplicaSet 파드가 완전히 사용 가능해지고 승격될 준비가 됨
- Rollout이 active service의 label selector를 (V1에서) V2 스택으로 업데이트해 승격(promote)
- 알 수 없는 문제(예: AWS load balancer controller 다운타임, AWS rate limiting)로 V2 Pod IP의 TargetGroup 등록이 일어나지 않거나 지연
- V1 ReplicaSet이 업데이트를 완료하기 위해 스케일다운
5단계 후 V1 ReplicaSet이 스케일다운되면, 뒤떨어진(outdated) TargetGroup이 더 이상 존재하지 않는 V1 Pod IP를 여전히 가리키므로 다운타임이 생겨요.
무중단 업데이트를 위해 Argo Rollouts은 업데이트 중 추가 안전 조치로 TargetGroup IP 검증을 수행할 수 있어요. 이 기능이 활성화되면, service selector 수정이 있을 때마다 Rollout 컨트롤러는 TargetGroup이 bluegreen.activeService의 새 Pod IP를 정확히 타깃으로 하는지 검증할 수 있을 때까지 업데이트 진행을 막아요. 검증은 AWS API를 쿼리해서 기반 TargetGroup을 설명(describe)하고, 등록된 IP를 순회하며 activeService의 Endpoints 목록의 모든 Pod IP가 TargetGroup에 등록됐는지 확인함으로써 이뤄져요. postPromotionAnalysis를 실행하거나 이전 ReplicaSet을 스케일다운하기 전에 검증이 성공해야 해요.
카나리아 전략도 마찬가지로, canary.stableService selector 라벨을 새 ReplicaSet으로 업데이트한 후 TargetGroup IP 검증 기능은 컨트롤러가 stableService TargetGroup 뒤의 Pod IP가 정확한지 검증할 때까지 이전 ReplicaSet의 스케일다운을 막을 수 있어요.
TargetGroup Weight 검증 (TargetGroup Weight Verification)
참고 (Note)
TargetGroup weight 검증은 Argo Rollouts v1.0부터 사용할 수 있어요.
TargetGroup weight 검증은 TargetGroup IP 검증과 비슷한 문제를 다루지만, service의 Pod IP가 TargetGroup에 정확히 반영되는지 확인하는 대신, 컨트롤러는 ingress annotation에 설정된 대로 트래픽 weight가 정확한지 확인해요. Weight 검증은 IP 모드 또는 Instance 모드로 실행되는 AWS LoadBalancer controller에 적용돼요.
Argo Rollouts이 Ingress annotation을 업데이트해서 카나리아 weight를 조정한 뒤 다음 단계로 이동해요. 하지만 외부 요인(예: AWS rate limiting, AWS load balancer controller 다운타임) 때문에 Ingress에 가한 weight 변경이 기반 TargetGroup에 반영되지 않았을 수 있어요. 컨트롤러가 이전 stable 스택을 스케일다운해도 안전하다고 믿는 반면, 실제로는 뒤떨어진 TargetGroup이 여전히 그것을 가리킬 수 있으므로 위험해요.
TargetGroup weight 검증 기능을 사용하면 rollout 컨트롤러는 setWeight 카나리아 단계 후에 카나리아 weight를 추가로 검증해요. 이를 위해 AWS LoadBalancer API를 직접 쿼리해서 Rules, Actions, TargetGroups가 Ingress annotation의 의도를 반영하는지 확인해요.
사용법 (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
참고 (Note)
--aws-region 플래그는 TargetGroup 검증을 포함한 AWS 통합을 활성화하는 데 필수예요. Argo Rollouts 컨트롤러에 올바른 AWS region이 지정되지 않았거나 AWS ALB를 검증할 권한이 없으면 승격(promotion) 프로세스가 실패해요. 컨트롤러에 필요한 AWS API 권한이 부여되고 region이 올바르게 구성됐는지 확인하세요.
이 기능이 동작하려면 argo-rollouts deployment에 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 파드에 AWS 권한을 부여하는 방법은 여러 가지가 있는데, 이는 클러스터의 AWS 환경에 크게 의존하며 이 문서의 범위 밖이에요. 일부 해결책은 다음과 같아요.
- AWS access and secret keys
- kiam
- kube2iam
- EKS ServiceAccount IAM Roles
Ping-Pong 기능으로 무중단 업데이트 (Zero-Downtime Updates with Ping-Pong feature)
위에서 설명했듯이 AWS는 IP 모드로 AWS LoadBalancer를 실행할 때 무중단 업데이트를 위해 pod readiness gate 주입을 권장해요. 하지만 이 접근 방식에는 문제가 있어요. Service selector 라벨(spec.selector)의 변경이 AWS LoadBalancer controller가 readiness gates를 변경하지 못하게 해요.
Ping-Pong 기능은 이 문제를 해결하는 데 도움을 줘요. 주어진 시점에 한 service(예: ping)가 안정 service로, 다른 service(예: pong)가 카나리아로 동작해요. 승격 단계가 끝나면 100%의 트래픽이 "카나리아"(예: pong)로 보내져요. 그러면 Rollout이 ping과 pong service의 역할을 바꿔서 pong이 새 안정 service가 돼요. Rollout status 객체는 status.canary.currentPingPong 필드를 통해 현재 어떤 service가 안정인지 추적해요. 이 접근 방식은 service들이 롤아웃 프로세스 전반에 걸쳐 라벨을 유지하므로 pod readiness gate 주입을 사용할 수 있게 해요.
중요 (Important)
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: {}
사용자 지정 annotation 접두사 (Custom annotations-prefix)
AWS Load Balancer Controller는 사용자가 컨트롤러에 --annotations-prefix 플래그(기본값 alb.ingress.kubernetes.io)를 사용해 Ingress controller가 사용하는 annotation 접두사를 사용자 지정할 수 있게 해요. AWS Load Balancer Controller가 다른 annotation 접두사를 사용하도록 사용자 지정됐다면, Ingress 객체가 클러스터의 aws load balancer controller가 이해하는 방식으로 주석이 달리도록 annotationPrefix 필드를 지정해야 해요.
apiVersion: argoproj.io/v1alpha1
kind: Rollout
spec:
strategy:
canary:
trafficRouting:
alb:
annotationPrefix: custom.alb.ingress.kubernetes.io
사용자 지정 Ingress Class (Custom Ingress Class)
기본적으로 Argo Rollout은 다음 annotation이 있는 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
다른 class 이름의 Ingress에서 동작하도록 컨트롤러를 설정하려면, 컨트롤러 명령줄 인수에서 --alb-ingress-classes 플래그로 다른 값을 지정할 수 있어요.
Argo Rollouts 컨트롤러가 여러 값에서 동작해야 한다면 --alb-ingress-classes 플래그를 여러 번 지정할 수 있다는 점에 주의하세요. 클러스터에 서로 다른 kubernetes.io/ingress.class 또는 spec.ingressClassName 값에서 동작하는 여러 Ingress controller가 있을 때 바람직할 수 있어요.
kubernetes.io/ingress.class annotation이나 spec.ingressClassName이 없는 모든 Ingress에서 컨트롤러가 동작해야 한다면, 플래그를 빈 문자열로 지정할 수 있어요(예: --alb-ingress-classes '').