KEDA Azure Monitor scaler: AGC 요청 수 기반 확장과 지표 지연¶
Application Gateway for Containers의 TotalRequests 메트릭을 KEDA azure-monitor scaler로 조회해 앱 수정 없이 진입점 트래픽으로 확장하는 구성과, 지표 지연에 따른 반응 시간, frontend NSG 조건을 다룹니다.
Application Gateway for Containers(AGC)는 frontend가 처리한 요청 수를
TotalRequests 플랫폼 메트릭으로 내보냅니다. KEDA add-on의 내장 azure-monitor scaler가
이 값을 Workload Identity로 읽고, KEDA가 만든 HPA가 Pod당 목표값으로 replica를
계산합니다. 앱에 지표를 추가하지 않고도 진입점 트래픽으로 확장할 수 있습니다. 다만 1분 단위 집계와 게시 지연 때문에 1회 실측에서는 첫 확장이
Managed Prometheus 방식보다 약 80초 늦었습니다.
확장 조건: 1분 집계 TotalRequests와 Pod당 목표값¶
| 항목 | 값 |
|---|---|
| 지표 | Microsoft.ServiceNetworking/trafficControllers 의 TotalRequests (집계 Total, 1분 단위, 차원 Frontend) |
| scaler | azure-monitor, metricAggregationInterval: "0:1:0", targetValue: "3000" |
| 인증 | KEDA Workload Identity + AGC 리소스 Monitoring Reader |
| 범위 | AGC 전체 요청 수. 여러 앱이 같은 AGC를 쓰면 metricFilter로 frontend를 나눕니다. |
사전 조건: Workload Identity·preview 기능 등록·서브넷 NSG¶
Managed Prometheus 실습과 같은 클러스터·podinfo·KEDA ID를
사용합니다. AGC add-on은 Azure CNI 또는 Azure CNI Overlay와 Workload Identity가 켜진
클러스터를 요구합니다. KEDA add-on은 Workload Identity 없이도 켜집니다. 다만 Azure 지표를
Workload Identity로 읽으려면 Workload Identity를 먼저 켜는 순서가 권장되며, 순서가
바뀌었으면 keda-operator를 재시작합니다.
AGC add-on은 preview입니다. postprovision hook(infra/enable-addons.sh)은 Learn quickstart와
같이 alb·aks-preview CLI extension을 설치하고 ManagedGatewayAPIPreview·
ApplicationLoadBalancerPreview feature가 Registered가 될 때까지 기다립니다. 이어서
Microsoft.ContainerService, Microsoft.Network, Microsoft.NetworkFunction,
Microsoft.ServiceNetworking provider 등록을 --wait로 완료한 뒤 add-on을 켭니다.
feature 등록은 처음 한 번 몇 분 걸릴 수 있습니다.
AKS 관리 VNet에서는 add-on이 Microsoft.ServiceNetworking/trafficControllers로
delegation된 aks-appgateway 서브넷을 만듭니다. Learn에는 이 서브넷의 NSG를 add-on이
만든다는 설명이 없습니다. 실습 구독에서는 서브넷이 생긴 뒤 이름에 appgateway가 들어간
NSG가 기본 규칙만 있는 상태로 연결되었습니다. azd로 다시 만든 클러스터에서는 add-on 설정 직후에는 NSG가
없다가 부하 실험 전에 연결되어 frontend가 막혔습니다. NSG를 연결한 주체는 확인하지 못했고(구독 정책
등으로 추정), NSG가 나중에 붙을 수 있으므로 부하를 주기 직전에 서브넷 상태를 다시 확인합니다.
비용: AGC·frontend·association 시간, capacity unit, 추가 노드¶
AGC 과금 미터는 AGC 리소스 시간, frontend 시간, association 시간, capacity unit
네 가지입니다. capacity unit은 persistent connection 수와 처리량(Mbps) 중 사용률이
높은 쪽으로 계산하며, 요청 수 자체는 미터가 아닙니다. Learn의 East US 2 예시
단가에서는 association 시간이 가장 큰 고정 비용입니다. 여기에 확장 중 NAP가 추가하는
노드 비용이 더해집니다. 실습 후 Gateway와 ApplicationLoadBalancer를 지우면 ALB Controller가
AGC 리소스를 삭제합니다.
준비와 실행: AGC Gateway, frontend NSG, 지표 읽기 권한, ScaledObject¶
AGC 준비는 postprovision hook이 다음 순서로 진행합니다.
- AKS 관리 VNet의
aks-appgateway서브넷 ID로agc/gateway.yaml의ApplicationLoadBalancerassociation을 채워 Gateway·HTTPRoute를 만들고Programmed상태를 기다립니다. agc/allow-frontend.sh가aks-appgateway서브넷에 NSG가 연결되어 있으면 TCP 80·443 inbound를 허용하고, 없으면 건너뜁니다. postdeploy hook은 부하 직전에 이 스크립트를 다시 실행하고 클러스터 안에서 frontend가 200을 돌려줄 때까지 기다립니다.- ALB Controller가 node resource group에 만든 AGC(
trafficControllers)에 KEDA ID의Monitoring Reader역할을 부여합니다.
부하는 postdeploy hook으로 실행합니다.
azd env set PATTERN azure-monitor-agc
azd hooks run postdeploy # 결과: out/<환경 이름>/azure-monitor-agc.csv, azure-monitor-agc-state.txt
hook은 agc/scaledobject.yaml의 <...> 값(AGC 이름, node resource group, 구독·테넌트, KEDA
client ID)을 채워 적용하고, k6로 Gateway 주소(http://<gateway-address>/)에 다른 패턴과 같은
부하(1분 ramp-up → 초당 400건 5분 유지 → 30초 감소)를 보냅니다.
실측 결과: 첫 확장과 전체 Ready 시점¶
k6 컨테이너 시작을 0초로 둔 1회 관측값입니다(AKS 1.36.5, 워크로드 노드는 NAP default
NodePool의 on-demand VM). 클러스터 안의 watcher Job이 5초 간격으로 기록한
results/azure-monitor-agc.csv, results/prometheus-rps.csv 기준이므로 시점은 근삿값입니다.
| 시점 | AGC + Azure Monitor | 비교: Managed Prometheus |
|---|---|---|
| 지표가 처음 0보다 커짐 | 약 95초 | 약 30초 |
| 첫 확장 | 약 155초 | 약 70초 |
| 목표 replica 8 도달 | 약 230초 | 약 130초 |
| 전체 Ready (NAP 노드 추가 포함) | 약 320초 | 약 255초 |
| 축소 시작 | 부하 종료 후 약 7분 | 부하 종료 후 약 3분 |
- k6 결과(
results/k6-summary.csv): 137,999건, 실패 0건, p99 2.58 ms TotalRequests는 1분 단위로 집계되어 부하 시작 약 95초 뒤에 처음 값이 조회됐고, 이후에도 값이 갱신되기 전까지 KEDA는 이전 값을 썼습니다. 기록 중간에 HPA 지표가 잠시 비는 구간도 있었습니다.- 축소는 마지막 지표가 반영되는 시간에 HPA 300초 안정화 창이 더해져 Prometheus 방식보다 늦었습니다.
적합한 경우: 급증보다 지속 트래픽¶
- 앱 코드와 모니터링을 바꾸지 않고 진입점 기준으로 확장할 수 있습니다.
- 급증에 더 빨리 반응해야 하면 이번 1회 실측에서 첫 확장이 빨랐던 Managed Prometheus(약 70초)나 HTTP Add-on(약 40초)을 먼저 검토합니다.
- AGC 하나를 여러 앱이 공유하면 전체 요청 수가 섞이므로 앱별 frontend를 나누고
metricFilter: Frontend eq '<frontend-name>'로 범위를 좁힙니다.
성공 기준: ScaledObject Ready와 분당 요청 수를 따르는 HPA 목표¶
postdeploy hook은 마지막에 ScaledObject·HPA를 지우고 podinfo를 1개로 되돌립니다. 그래서 아래 kubectl
확인은 hook 실행 중 다른 터미널에서 하고, 종료 후에는 패턴이 끝난 직후 저장한
out/<환경 이름>/<패턴>-state.txt(ScaledObject·HPA·podinfo replica)와 결과 CSV의 desired·hpa_metric 열로 확인합니다.
kubectl -n demo get scaledobject podinfo:READY=Truekubectl -n demo get hpa keda-hpa-podinfo: 부하 중<값>/3k (avg)- 부하 중 replica가
ceil(분당 요청 / 3000)근처에 머물고 요청 실패가 없어야 합니다.
정리: azd down¶
클러스터를 남기고 AGC만 지울 때는 Gateway·HTTPRoute와 ApplicationLoadBalancer를 먼저
삭제해 ALB Controller가 AGC 리소스를 정리하게 합니다.
문제 해결: frontend 무응답과 association 서브넷 NSG¶
| 증상 | 원인과 조치 |
|---|---|
Gateway가 Programmed=True인데 frontend 연결이 timeout, NewConnections 0 |
2026-04-23 이후 만든 association에는 서브넷 NSG의 inbound·outbound 규칙이 모두 적용됩니다. 실습 구독에서 연결된 aks-appgateway NSG에는 기본 규칙(AllowVNetInBound, AllowAzureLoadBalancerInBound, DenyAllInBound)만 있어 Internet에서 오는 80·443이 DenyAllInBound에 막혔습니다. Internet → TCP 80·443 허용 규칙 추가. AzureLoadBalancer 허용도 유지 |
HPA TARGETS가 <unknown> |
KEDA ID에 AGC 리소스 Monitoring Reader가 없거나 resourceURI·resourceGroupName이 노드 리소스 그룹(MC_)이 아님 |
ALB Controller 로그에 no Pods found for Service |
백엔드 Deployment가 0개. azure-monitor scaler는 minReplicaCount: 1 이상으로 둠 |
공식 참고 자료¶
- Integrations with KEDA on AKS
- KEDA add-on and workload identity
- Deploy ALB Controller using AKS add-on
- Create AGC managed by ALB Controller
- Application Gateway for Containers components (NSG)
- Metrics for AGC
- Understanding Pricing for AGC
- Azure network security groups overview (기본 규칙)
- KEDA Azure Monitor scaler
참고 문서
- Integrations with Kubernetes Event-driven Autoscaling (KEDA) on Azure Kubernetes Service (AKS)
- Securely scale your applications using the KEDA add-on and workload identity on Azure Kubernetes Service (AKS)
- Quickstart: Deploy Application Gateway for Containers ALB Controller using AKS Add-on
- Quickstart: Create Application Gateway for Containers managed by ALB Controller
- Application Gateway for Containers components
- Metrics for Application Gateway for Containers
- Understanding Pricing for Application Gateway for Containers
- Azure network security groups overview
- Simplified application autoscaling with Kubernetes Event-driven Autoscaling (KEDA) add-on
- KEDA Azure Monitor scaler