📈 HPA Scales Pods. VPA Scales Pod Resources.
Guessing CPU/memory requests is hard. Vertical Pod Autoscaler recommends or automatically adjusts resource requests based on actual usage.
📝 Install VPA
git clone https://github.com/kubernetes/autoscaler.git cd autoscaler/vertical-pod-autoscaler ./hack/vpa-up.sh kubectl get pods -n kube-system | grep vpa
🎯 VPA Configuration
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: myapp-vpa
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp
updatePolicy:
updateMode: "Auto" # or "Off", "Initial", "Recreate"
resourcePolicy:
containerPolicies:
- containerName: '*'
minAllowed:
cpu: 100m
memory: 256Mi
maxAllowed:
cpu: 2
memory: 4Gi
# updateMode:
# - Off: Only recommendations, no changes
# - Initial: Set requests at creation only
# - Auto: Automatically update pods (may restart)
# - Recreate: Restart pods when needed
✅ Check Recommendations
kubectl describe vpa myapp-vpa # Output shows: # Recommendation: # Container Recommendations: # Container Name: myapp # Lower Bound: cpu: 250m, memory: 512Mi # Target: cpu: 500m, memory: 1Gi # Upper Bound: cpu: 1, memory: 2Gi # Uncapped Target: cpu: 800m, memory: 1.5Gi # Apply recommendations manually kubectl edit deployment myapp # Update requests to match Target values
💡 Best Practices
- Start with updateMode: “Off” to see recommendations first
- Set minAllowed to prevent under-provisioning
- Set maxAllowed to prevent runaway pods
- Don’t use VPA with HPA on same metrics (CPU/memory)
- VPA may restart pods to apply changes
“Guessed CPU requests: 2 cores (over-provisioned). VPA recommended 500m. Saved 75% CPU cost. Memory recommendations saved another 50%. VPA paid for itself in a week.”
