VPA
Vertical Pod Autoscaler, Pod 리소스를 자동 조정
Vertical Pod Autoscaler, Pod 리소스를 자동 조정
VPA(Vertical Pod Autoscaler)는 Pod의 CPU와 메모리 리소스 요청(requests)과 제한(limits)을 자동으로 조정하는 Kubernetes 컴포넌트입니다. 실제 사용량을 모니터링하여 최적의 리소스 값을 추천하거나 자동으로 적용합니다.
VPA 구성요소:
업데이트 모드(updatePolicy.updateMode):
HPA vs VPA:
주의: HPA와 VPA를 같은 리소스(CPU 또는 메모리)에 동시 적용하면 충돌할 수 있습니다. VPA는 Off 모드로 추천만 확인하거나, 다른 메트릭을 기준으로 HPA를 사용하세요.
# VPA 설치 (autoscaler 저장소에서)
git clone https://github.com/kubernetes/autoscaler.git
cd autoscaler/vertical-pod-autoscaler
./hack/vpa-up.sh
# 또는 Helm으로 설치
helm repo add fairwinds-stable https://charts.fairwinds.com/stable
helm install vpa fairwinds-stable/vpa --namespace vpa --create-namespace
# 설치 확인
kubectl get pods -n kube-system | grep vpa
# vpa-admission-controller-xxx Running
# vpa-recommender-xxx Running
# vpa-updater-xxx Running
# vpa.yaml
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: my-app-vpa
spec:
# 대상 워크로드
targetRef:
apiVersion: apps/v1
kind: Deployment
name: my-app
# 업데이트 정책
updatePolicy:
updateMode: "Auto" # Off, Initial, Recreate, Auto
# 리소스 정책 (세부 제어)
resourcePolicy:
containerPolicies:
- containerName: "*" # 모든 컨테이너
minAllowed:
cpu: 100m
memory: 128Mi
maxAllowed:
cpu: 2
memory: 4Gi
controlledResources: ["cpu", "memory"]
controlledValues: RequestsAndLimits # RequestsOnly 가능
---
# 대상 Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: app
image: my-app:latest
resources:
requests:
cpu: 100m # VPA가 자동 조정
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
# VPA 추천값 확인
kubectl describe vpa my-app-vpa
# 출력 예시:
# Recommendation:
# Container Recommendations:
# Container Name: app
# Lower Bound:
# Cpu: 25m
# Memory: 262144k
# Target: # 권장 값
# Cpu: 50m
# Memory: 524288k
# Uncapped Target:
# Cpu: 50m
# Memory: 524288k
# Upper Bound:
# Cpu: 100m
# Memory: 1048576k
# JSON으로 추천값만 추출
kubectl get vpa my-app-vpa -o jsonpath='{.status.recommendation.containerRecommendations[0].target}'
# {"cpu":"50m","memory":"524288k"}
# 모든 VPA 추천값 확인
kubectl get vpa -o custom-columns=\
NAME:.metadata.name,\
CPU_TARGET:.status.recommendation.containerRecommendations[0].target.cpu,\
MEM_TARGET:.status.recommendation.containerRecommendations[0].target.memory
FinOps: "클러스터 비용이 너무 높아요. 리소스 requests가 과도한 것 같은데요."
개발자: "VPA를 Off 모드로 설정해서 추천값을 먼저 확인해볼게요. 실제 사용량 대비 얼마나 과할당되었는지 파악할 수 있어요."
FinOps: "자동 적용은요?"
개발자: "스테이징에서 Auto 모드로 테스트하고, 안정적이면 프로덕션에 적용해요. 다만 Pod 재시작이 발생하니까 영향도 체크해야 해요."
면접관: "HPA와 VPA를 함께 사용할 수 있나요?"
지원자: "같은 메트릭(CPU, 메모리)으로 동시 사용하면 충돌합니다. VPA가 requests를 높이면 HPA가 스케일다운하고, 다시 VPA가 조정하는 루프가 생길 수 있어요."
면접관: "그럼 어떻게 해야 하죠?"
지원자: "VPA는 Off 모드로 추천만 받고, HPA로 스케일링하는 게 일반적이에요. 아니면 VPA는 메모리만, HPA는 CPU나 커스텀 메트릭으로 분리하는 방법도 있습니다."
운영팀: "Pod가 자꾸 재시작돼요. OOMKilled도 아닌데..."
개발자: "VPA Updater가 리소스 범위 벗어난 Pod를 퇴거시키는 거예요. kubectl describe pod 보면 evicted by VPA 이벤트가 있을 거예요."
운영팀: "잠깐 멈출 수 있나요?"
개발자: "updateMode를 Off로 바꾸면 추천만 하고 퇴거 안 해요. 안정화되면 다시 Auto로 변경하면 됩니다."