Implementing Vertical Pod Autoscaling

1. Installing VPA Components

git clone https://github.com/kubernetes/autoscaler
cd autoscaler/vertical-pod-autoscaler && ./hack/vpa-up.sh
ComponentRole
RecommenderCompute resource recommendations
UpdaterEvict pods needing new resources
Admission PluginMutate pod requests at creation

2. Creating VPA Resource

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata: { name: web-vpa }
spec:
  targetRef: { apiVersion: apps/v1, kind: Deployment, name: web }
  updatePolicy: { updateMode: Auto }
  resourcePolicy:
    containerPolicies:
    - containerName: '*'
      minAllowed: { cpu: 100m, memory: 128Mi }
      maxAllowed: { cpu: "2",  memory: 2Gi }
      controlledResources: ["cpu","memory"]

3. Setting Update Mode

ModeBehavior
OffOnly recommendations, no mutation
InitialSet at pod creation only
RecreateEvict to apply new values
AutoCurrently same as Recreate; in-place coming
InPlaceOrRecreate NEW1.30+ in-place pod resize

4. Configuring Resource Policy

FieldUse
minAllowed / maxAllowedBound recommendations
controlledResourcescpu, memory
controlledValuesRequestsAndLimits / RequestsOnly
mode (per container)Auto / Off

5. Setting Min Allowed Resources

minAllowed: { cpu: 100m, memory: 128Mi }

6. Setting Max Allowed Resources

maxAllowed: { cpu: "4", memory: 8Gi }

7. Viewing VPA Recommendations

kubectl get vpa web-vpa -o yaml
kubectl describe vpa web-vpa
FieldMeaning
lowerBoundMinimum recommended (avoid eviction)
targetOptimal value
upperBoundMaximum projected
uncappedTargetWithout min/max applied

8. Understanding VPA Components

VPA Pipeline

metrics → Recommender → VPA.status → Updater → evict pods
                          ↓
                    Admission Plugin (rewrites new pod requests)
        

9. Using VPA with HPA

CombinationRecommendation
HPA on CPU + VPA Auto on CPUConflicts; avoid
HPA on custom metric + VPA on CPU/memorySafe; complementary
VPA Off (recommend-only) + HPAUse VPA for rightsizing analysis

10. Deleting VPA Resources

kubectl delete vpa web-vpa
./hack/vpa-down.sh   # remove all VPA components