Difficulty: Advanced
What is the Vertical Pod Autoscaler (VPA), how does it work, and when would you use it instead of or alongside the HPA?
The Vertical Pod Autoscaler automatically sets CPU and memory requests (and proportionally limits) for containers based on their observed usage. Instead of adding more Pods like the Horizontal Pod Autoscaler, it makes each Pod the right size, which fixes over-provisioned services that waste money and under-provisioned ones that get throttled or OOMKilled.
VPA is not part of core Kubernetes; you install it from the kubernetes/autoscaler project (GKE offers it as a built-in option). It has three parts:
target, lowerBound, upperBound and uncappedTarget.| Mode | Behaviour |
|---|---|
Off | Only computes recommendations; nothing changes |
Initial | Sets requests at Pod creation, never evicts |
Recreate | Sets at creation and evicts Pods to apply new values |
Auto | Currently behaves like Recreate |
InPlaceOrRecreate | Newer mode that resizes running Pods in place where possible |
Kubernetes added in-place Pod resize (changing a running container's CPU and memory without restarting the Pod), which became beta and enabled by default in 1.33 and later graduated to stable. VPA's InPlaceOrRecreate mode builds on it, falling back to eviction when an in-place resize is not possible. Check your cluster and VPA versions before relying on it.
Off mode purely for recommendations.updateMode: "Off" and read the recommendations with kubectl describe vpa. Many teams use VPA only as a right-sizing report.resourcePolicy with minAllowed and maxAllowed so a bad week of data cannot shrink a container to nothing or grow it beyond node size.Recreate mode. By default the updater will not evict when fewer than two live replicas exist.controlledValues: RequestsOnly leaves limits alone; the default RequestsAndLimits scales limits to keep the original ratio.apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: invoice-worker
namespace: billing
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: invoice-worker
updatePolicy:
updateMode: "Off" # start with recommendations only
resourcePolicy:
containerPolicies:
- containerName: "*"
minAllowed:
cpu: 100m
memory: 128Mi
maxAllowed:
cpu: "2"
memory: 2Gi
controlledValues: RequestsAndLimits
Off mode is a safe first step; switch to Initial or Recreate once the recommendations look sensible.
kubectl describe vpa invoice-worker -n billing | sed -n '/Recommendation/,$p'
Target is what VPA would set; lower and upper bounds show how confident it is.
Vertical Pod Autoscaler, Resource Requests, Recommender, updateMode, In-place Pod Resize