VPA (Vertical Pod Autoscaler)는 Kubernetes에서 Pod의 리소스 요청 값(Requests)을 최적화하여 자동 조정하는 기능을 제공합니다. CPU 및 메모리 사용량을 분석하여 적절한 리소스를 할당하고, 필요에 따라 Pod를 재시작하여 새로운 리소스 값을 적용합니다.
| 비교 항목 | HPA (Horizontal Pod Autoscaler) | VPA (Vertical Pod Autoscaler) |
|---|---|---|
| 기반 메트릭 | CPU, Memory 사용률 | CPU, Memory 사용량 분석 |
| 스케일링 방식 | Pod 개수를 증가/감소 | 개별 Pod의 리소스 요청값 변경 |
| Pod 재시작 여부 | ❌ 재시작 없음 | ✅ 필요 시 Pod 재시작 |
| HPA와 동시 사용 가능 여부 | ✅ 가능 | ❌ 불가능 |
| Scale to Zero 지원 | ❌ 미지원 | ❌ 미지원 |
VPA는 HPA와 함께 사용할 수 없으며, Pod의 리소스를 조정하기 위해 기존 Pod를 종료하고 새로운 Pod를 실행합니다.
VPA는 Pod의 리소스를 최적화하기 위해 아래와 같은 단계를 거칩니다.
리소스 요청 값(Requests) 결정
Pod가 실행되는데 필요한 최소한의 CPU 및 메모리 값을 측정합니다.
마진 값(Buffers) 추가
약간의 여유 값을 추가하여 예측 오차를 보정합니다.
리소스 업데이트 정책 적용
VPA 설정에 따라 Pod 리소스를 자동 변경하고, 필요 시 Pod를 재시작합니다.
updateMode: "Auto" → Pod의 리소스를 자동으로 변경하고 재시작 (기본값)updateMode: "Off" → 리소스 추천값을 확인하되, 자동 적용하지 않음updateMode: "Initial" → 신규 생성되는 Pod에만 적용VPA는 Helm Chart 또는 직접 배포 스크립트를 이용하여 설치할 수 있습니다.
Kubernetes 클러스터에서 VPA 설치를 위해 openssl 버전을 확인하고 최신 버전으로 업그레이드해야 합니다.
# [운영서버 EC2]
cd ~/autoscaler/vertical-pod-autoscaler/
tree hack
# openssl 버전 확인
openssl version
# 결과 예시
OpenSSL 1.0.2k-fips 26 Jan 2017
# 기존 OpenSSL 1.0 제거
yum remove openssl -y
# 최신 OpenSSL 설치
yum install openssl11 -y
# openssl 1.1.1 이상 버전 확인
openssl11 version
# 결과 예시
OpenSSL 1.1.1g FIPS 21 Apr 2020
# 스크립트 내에 openssl11 버전 업데이트
sed -i 's/openssl/openssl11/g' ~/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/gencerts.sh
git status
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git add .
git commit -m "openssl version modify"
# Deploy the Vertical Pod Autoscaler to your cluster with the following command.
watch -d kubectl get pod -n kube-system
cat hack/vpa-up.sh
# VPA 배포 스크립트 실행
./hack/vpa-up.sh
# 재실행!
sed -i 's/openssl/openssl11/g' ~/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/gencerts.sh
./hack/vpa-up.sh
# VPA 정상 설치 확인
kubectl get crd | grep autoscaling
kubectl get mutatingwebhookconfigurations vpa-webhook-config
kubectl get mutatingwebhookconfigurations vpa-webhook-config -o json | jq








VPA는 Kubernetes의 Mutating Webhook을 활용하여 리소스 값을 변경하므로, Webhook 설정이 정상적으로 반영되어야 합니다.
VPA는 실행 중인 Pod의 리소스 요청 값을 자동으로 변경하고, 필요 시 Pod를 재시작합니다.
VPA는 Kubernetes 애플리케이션의 리소스를 최적화하여 변경하는 기능을 수행합니다. 이를 실습하기 위해 Hamster 예제 애플리케이션을 배포합니다.
# VPA 모니터링
watch -d "kubectl top pod;echo "----------------------";kubectl describe pod | grep Requests: -A2"
# 공식 예제 배포
cd ~/autoscaler/vertical-pod-autoscaler/
cat examples/hamster.yaml
kubectl apply -f examples/hamster.yaml && kubectl get vpa -w
# VPA가 적용된 파드 리소스 Requestes 확인
kubectl describe pod | grep Requests: -A2
Requests:
cpu: 100m
memory: 50Mi
--
Requests:
cpu: 587m
memory: 262144k
--
Requests:
cpu: 587m
memory: 262144k
# VPA에 의해 기존 파드 삭제되고 신규 파드가 생성됨
kubectl get events --sort-by=".metadata.creationTimestamp" | grep VPA
2m16s Normal EvictedByVPA pod/hamster-5bccbb88c6-s6jkp Pod was evicted by VPA Updater to apply resource recommendation.
76s Normal EvictedByVPA pod/hamster-5bccbb88c6-jc6gq Pod was evicted by VPA Updater to apply resource recommendation.







VPA는 기존 Pod를 강제 종료하고, 새로운 리소스 값을 가진 Pod를 실행하는 방식으로 동작합니다.
kube_customresource_vpa_containerrecommendations_target{resource="cpu"}
kube_customresource_vpa_containerrecommendations_target{resource="memory"}


kubectl delete -f examples/hamster.yaml && cd ~/autoscaler/vertical-pod-autoscaler/ && ./hack/vpa-down.sh

VPA를 완전히 제거하려면 CRD 및 Webhook 설정도 삭제해야 합니다.