VPA
Vertical Pod Autoscaler, automatically adjusts Pod resources
Vertical Pod Autoscaler, automatically adjusts Pod resources
VPA (Vertical Pod Autoscaler) is a Kubernetes component that automatically adjusts the CPU and memory resource requests and limits of Pods. It monitors actual usage to recommend optimal resource values or apply them automatically.
VPA components:
Update modes (updatePolicy.updateMode):
HPA vs VPA:
Note: Applying HPA and VPA simultaneously to the same resource (CPU or memory) can cause conflicts. Use VPA in Off mode to only review recommendations, or use HPA based on a different metric.
# 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: "Our cluster costs are too high. It seems like the resource requests are excessive."
Developer: "I'll set VPA to Off mode and check the recommendations first. We can see how much we're over-provisioned compared to actual usage."
FinOps: "What about automatic application?"
Developer: "We'll test it in Auto mode on staging, and if it's stable, apply it to production. But Pods restart, so we need to check the impact."
Interviewer: "Can HPA and VPA be used together?"
Candidate: "Using them simultaneously on the same metrics (CPU, memory) causes conflicts. When VPA raises the requests, HPA scales down, and then VPA adjusts again, which can create a loop."
Interviewer: "So what should we do?"
Candidate: "It's common to use VPA in Off mode for recommendations only and scale with HPA. Alternatively, you can separate them: VPA for memory only, and HPA for CPU or custom metrics."
Operations team: "Pods keep restarting. It's not even OOMKilled..."
Developer: "It's the VPA Updater evicting Pods that fall outside the resource range. If you run kubectl describe pod, you should see an evicted by VPA event."
Operations team: "Can we pause it for a moment?"
Developer: "If you change updateMode to Off, it only makes recommendations and doesn't evict. Once things stabilize, you can switch it back to Auto."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free