Skip to content
LF Cert Trainer

Lesson 60 · Section 5: Application Lifecycle Management

Lesson 60: Vertical Pod Autoscaling: let the cluster choose requests and limits

What the Vertical Pod Autoscaler is and why it is an add-on, how its recommender, updater and admission webhook turn measured usage into new requests, what each update mode does to your Pods, and how to write, read and troubleshoot a VerticalPodAutoscaler in the exam. · 20 min read · 4 min video

1/10Vertical Pod Autoscaling
0:00 / 4:17

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why it exists

Every container should carry a CPU and memory request, because the scheduler places Pods by their requests and the node protects them by the same numbers. The trouble is where those numbers come from. Most of the time somebody guessed them once, on the day the manifest was written:

  • Guess too high and the node reserves room nobody uses. A Pod that requests 1 CPU and uses 50m still blocks a whole CPU from every other Pod, and the cluster looks full while it is nearly idle.
  • Guess too low and too many Pods are packed onto a node. Under load they are throttled, and when memory runs short they are evicted or OOMKilled.
  • Guess right and it is still only right for a while. Traffic grows, a release adds a cache, a nightly job behaves differently from the daytime service.

The Vertical Pod Autoscaler (VPA) takes this job over. It measures what each container really uses, works out what its requests should be, and can apply those values for you.

What it is

Two ways to answer more loadreplicasrequestsMore load2 Pods × 100m CPUHorizontalHorizontalPodAutoscalerVerticalVerticalPodAutoscalerMore Pods4 Pods × 100m CPUBigger Pods2 Pods × 250m CPU
Two ways to answer more load. Horizontal scaling changes how many Pods there are. Vertical scaling changes how much CPU and memory each Pod asks for.

Parts:

  • More load (2 Pods × 100m CPU)
  • Horizontal (HorizontalPodAutoscaler)
  • Vertical (VerticalPodAutoscaler)
  • More Pods (4 Pods × 100m CPU)
  • Bigger Pods (2 Pods × 250m CPU)

Connections:

  • More load to Horizontal
  • More load to Vertical
  • Horizontal to More Pods: replicas
  • Vertical to Bigger Pods: requests
Horizontal Pod AutoscalerVertical Pod Autoscaler
Changesspec.replicas of the workloadresources.requests (and limits) of the Pods
Reacts toCurrent load against a target, within seconds to minutesUsage history, over hours to days
APIautoscaling/v2, built into Kubernetesautoscaling.k8s.io/v1, a custom resource from an add-on
Good forStateless services that can run many copiesWorkloads that cannot simply add copies, or whose size nobody knows
Cost of a changeA Pod is added or removedA Pod is restarted, or resized in place

The most important line in that table is the third. VPA is not part of core Kubernetes. It comes from the kubernetes/autoscaler project and has to be installed in the cluster: custom resource definitions plus three small Deployments in kube-system. It also needs the Metrics Server, the same source kubectl top and the Horizontal Pod Autoscaler read from. If kubectl get vpa answers the server doesn't have a resource type "vpa", the add-on is not there.

Once it is installed, you describe what you want with a VerticalPodAutoscaler object:

FieldMeaningDefault
spec.targetRefThe workload to size: a Deployment, StatefulSet, DaemonSet or another controller. Not a bare Podrequired
spec.updatePolicy.updateModeHow recommendations are applied: Off, Initial, Recreate, InPlaceOrRecreateRecreate behaviour
spec.updatePolicy.minReplicasThe fewest live replicas the workload must have before the updater may evict one2 (set on the updater)
spec.resourcePolicy.containerPolicies[].containerNameThe container the policy is for; "*" means every container without its own policynone
…minAllowed, …maxAllowedFloor and ceiling for the recommendationno bounds
…controlledResourcesWhich resources VPA manages: cpu, memory or bothboth
…controlledValuesRequestsAndLimits or RequestsOnlyRequestsAndLimits
…modeOff leaves that one container alone, for example a sidecarAuto

What VPA works out appears in the object's status, as one entry per container with four values:

ValueWhat it tells you
targetThe request VPA recommends. This is the number that is applied, and the one to copy if you set requests by hand
lowerBoundBelow this, the container is probably under-provisioned
upperBoundAbove this, the container is probably over-provisioned
uncappedTargetWhat the target would be without your minAllowed and maxAllowed. If it differs from target, your bounds are holding the recommendation back

How it works

The three parts of the Vertical Pod Autoscalerusagewritesreads the targetevictsgonecreates a PodpatchesMetrics ServerCPU and memory in useRecommenderkeeps a usage historyVPA objectstatus.recommendationUpdatercompares Pods to targetRunning Podrequests cpu: 100mReplicaSetone Pod shortNew Pod requeststill cpu: 100mVPA admissionmutating webhookNew Podrequests cpu: 250m
The three parts of the Vertical Pod Autoscaler. The recommender writes numbers, the updater removes Pods whose requests are too far off, and the admission webhook puts the new numbers into the replacement Pod.

Parts:

  • Metrics Server (CPU and memory in use)
  • Recommender (keeps a usage history)
  • VPA object (status.recommendation)
  • Updater (compares Pods to target)
  • Running Pod (requests cpu: 100m)
  • ReplicaSet (one Pod short)
  • New Pod request (still cpu: 100m)
  • VPA admission (mutating webhook)
  • New Pod (requests cpu: 250m)

Connections:

  • Metrics Server to Recommender: usage
  • Recommender to VPA object: writes
  • VPA object to Updater: reads the target
  • Updater to Running Pod: evicts
  • Running Pod to ReplicaSet: gone
  • ReplicaSet to New Pod request: creates a Pod
  • New Pod request to VPA admission
  • VPA admission to New Pod: patches

VPA is three separate programs. Like every other controller, none of them gives orders to another: they meet in the API server.

  1. The recommender reads CPU and memory usage from the Metrics Server and keeps a history for every container of the target workload. From that history it calculates the recommendation and writes it into status.recommendation of the VPA object. That is all it ever changes.
  2. The updater looks at the running Pods of the target. If a Pod's requests are outside the range between lowerBound and upperBound, it is worth disturbing, so the updater evicts it (or resizes it in place, in the mode that allows that).
  3. The workload's own controller, for a Deployment its ReplicaSet, sees that a Pod is missing and creates a new one from the unchanged Pod template, with the old requests.
  4. The VPA admission controller, a mutating admission webhook, intercepts that create request. It finds the VPA whose target owns the Pod and overwrites the requests with the target values before the Pod is stored.
  5. The scheduler now places a Pod with the new, measured requests.

Two things follow from this design, and both show up as exam traps:

  • The Deployment is never edited. kubectl get deployment web -o yaml still shows the requests you wrote. The real values are only on the Pods, together with an annotation that says VPA changed them.
  • An existing Pod is not changed by the webhook. A webhook only sees a Pod at the moment it is created. That is why the classic way to apply a recommendation is to remove the Pod and let it be created again.
Under the hood · Where the numbers come from

The recommender does not take an average. It keeps a weighted history of each container's usage, in which recent samples count more than old ones (about eight days by default), and picks a high percentile of it, then adds a safety margin. For memory it looks at peaks rather than typical use, and when a container is OOMKilled it raises the recommendation above the amount that failed. The result is deliberately a little generous: a request that covers almost all of what the container has been seen to need.

A few practical consequences:

  • It needs time. A VPA that was created a minute ago has nothing in its status, or a very rough first value. Recommendations settle after the workload has seen real traffic.
  • It has built-in minimums. By default the recommender does not go below about 25m of CPU and 250Mi of memory for a Pod, so a tiny container can receive a memory target far above what it uses. Set minAllowed and maxAllowed when you know better.
  • It cannot see what did not happen. A service that was never busy during the history gets a recommendation for quiet days.
Under the hood · What happens to limits

With the default controlledValues: RequestsAndLimits, VPA keeps the ratio between request and limit that you wrote in the Pod template. A container with a CPU request of 100m and a limit of 200m has a ratio of 1 to 2; when the target becomes 250m, the limit becomes 500m. A container with no limit stays without one.

Set controlledValues: RequestsOnly when the limit must stay exactly as written. VPA also respects a LimitRange in the namespace: a recommendation that would break its minimum or maximum is capped to fit, and you see that in the difference between target and uncappedTarget.

The update modes

What each update mode does with a recommendationRecommendationtarget cpu: 250mOffadvice onlyInitialat Pod creationRecreateevict and replaceInPlaceOrRecreateresize, else evictNothing changesread it in the statusNew Pods onlyrunning Pods are keptPods restartnew name, new IPSame Pod, resizedrestart only if needed
What each update mode does with a recommendation. The recommendation is always calculated. The update mode only decides how far the autoscaler may go in applying it.

Parts:

  • Recommendation (target cpu: 250m)
  • Off (advice only)
  • Initial (at Pod creation)
  • Recreate (evict and replace)
  • InPlaceOrRecreate (resize, else evict)
  • Nothing changes (read it in the status)
  • New Pods only (running Pods are kept)
  • Pods restart (new name, new IP)
  • Same Pod, resized (restart only if needed)

Connections:

  • Recommendation to Off
  • Recommendation to Initial
  • Recommendation to Recreate
  • Recommendation to InPlaceOrRecreate
  • Off to Nothing changes
  • Initial to New Pods only
  • Recreate to Pods restart
  • InPlaceOrRecreate to Same Pod, resized

The recommender always does its work. updatePolicy.updateMode only decides how much of the rest happens.

ModeNew Pods get the targetRunning PodsUse it when
OffNoNever touchedYou want advice only: read the target, then decide yourself. The safe first step
InitialYesNever touchedRestarts must happen on your schedule: values apply at the next rollout or scale-up
RecreateYesEvicted and replaced when too far from the recommendationThe workload has several replicas and tolerates restarts
InPlaceOrRecreateYesResized without a restart where possible; evicted only when the resize cannot be doneYou want updates with as little disruption as possible

InPlaceOrRecreate builds on the in-place Pod resize you met in the previous lesson, which is enabled by default from Kubernetes 1.33. The updater patches the Pod's resize subresource instead of evicting it. Whether a container restarts then depends on its resizePolicy, and if the node has no room for the bigger Pod, VPA falls back to eviction so the Pod can be scheduled elsewhere.

You will also meet two other values in manifests:

  • Auto is the old name. It has been deprecated since VPA 1.4.0 and today behaves exactly like Recreate. Write Recreate or InPlaceOrRecreate in new manifests, but recognise Auto when you read one.
  • InPlace is an alpha mode in recent VPA releases that resizes in place and never evicts: if the resize cannot be done yet, it waits and tries again. It needs feature gates on the VPA components, so do not expect it on an ordinary cluster.

Using it

Example · Check that VPA is installed, and install it when it is not

The quickest test is the custom resource definition, then the three components:

kubectl get crd | grep verticalpodautoscaler
kubectl -n kube-system get pods | grep vpa
kubectl top pods -A | head -3            # proves the Metrics Server answers
verticalpodautoscalercheckpoints.autoscaling.k8s.io   2026-11-30T09:12:44Z
verticalpodautoscalers.autoscaling.k8s.io             2026-11-30T09:12:44Z

vpa-admission-controller-6d9c8b7f5d-x2m8k   1/1   Running   0   2h
vpa-recommender-7f8d6c5b4-qw9zn             1/1   Running   0   2h
vpa-updater-5c7b9d8f6-h4t2v                 1/1   Running   0   2h

If nothing is there, install it from the autoscaler repository. The script creates the definitions, the RBAC rules, the webhook certificates and the three Deployments:

git clone https://github.com/kubernetes/autoscaler.git
cd autoscaler/vertical-pod-autoscaler
./hack/vpa-up.sh

./hack/vpa-down.sh removes it again. Managed clusters often offer VPA as a switch instead.

Example · Ask for a recommendation without touching the Pods

The Deployment web in the namespace shop runs with requests somebody guessed. Find out what they should be.

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: web-vpa
  namespace: shop
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: web
  updatePolicy:
    updateMode: "Off"
kubectl apply -f web-vpa.yaml
kubectl -n shop get vpa web-vpa
NAME      MODE   CPU    MEM       PROVIDED   AGE
web-vpa   Off    250m   262144k   True       6m

PROVIDED is True once a recommendation exists, and CPU and MEM show the target of the first container. For every container and all four values:

kubectl -n shop describe vpa web-vpa
Status:
  Conditions:
    Status:  True
    Type:    RecommendationProvided
  Recommendation:
    Container Recommendations:
      Container Name:  nginx
      Lower Bound:
        Cpu:     120m
        Memory:  262144k
      Target:
        Cpu:     250m
        Memory:  262144k
      Uncapped Target:
        Cpu:     250m
        Memory:  262144k
      Upper Bound:
        Cpu:     1
        Memory:  1Gi

To apply it by hand, copy the target into the Deployment, which starts a normal rolling update:

kubectl -n shop set resources deployment web -c nginx --requests=cpu=250m,memory=256Mi

Example · Let VPA apply its recommendations, inside bounds you choose

Now VPA may update the Pods of web, but the CPU request must stay between 50m and 1 CPU and the memory request between 64Mi and 1Gi.

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: web-vpa
  namespace: shop
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: web
  updatePolicy:
    updateMode: "Recreate"
  resourcePolicy:
    containerPolicies:
      - containerName: "*"
        minAllowed:
          cpu: 50m
          memory: 64Mi
        maxAllowed:
          cpu: "1"
          memory: 1Gi
        controlledResources: ["cpu", "memory"]
kubectl apply -f web-vpa.yaml
kubectl -n shop get pods -l app=web -w        # Pods are evicted and replaced one at a time

Then prove the new Pods carry the recommended requests, and that the Deployment does not:

kubectl -n shop get pods -l app=web \
  -o custom-columns='POD:.metadata.name,CPU:.spec.containers[0].resources.requests.cpu,MEM:.spec.containers[0].resources.requests.memory'
kubectl -n shop get deployment web -o jsonpath='{.spec.template.spec.containers[0].resources}{"\n"}'
POD                    CPU    MEM
web-5d4f8c7b9d-7xk2p   250m   262144k
web-5d4f8c7b9d-m9c4t   250m   262144k

{"requests":{"cpu":"100m","memory":"64Mi"}}

The Pods kept their ReplicaSet (web-5d4f8c7b9d): there was no rollout, only evictions.

Example · Resize in place, and leave the sidecar alone

The Deployment api has two containers, app and a logging sidecar log-agent. Size only app, only its memory request, and avoid restarts where the cluster can.

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: api-vpa
  namespace: shop
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  updatePolicy:
    updateMode: "InPlaceOrRecreate"
  resourcePolicy:
    containerPolicies:
      - containerName: app
        controlledResources: ["memory"]
        controlledValues: RequestsOnly
        maxAllowed:
          memory: 2Gi
      - containerName: log-agent
        mode: "Off"

After a resize the Pod keeps its name, its IP address and its age. The restart count of app tells you whether its resizePolicy asked for a container restart:

kubectl -n shop get pods -l app=api
kubectl -n shop get pod <pod> -o jsonpath='{.status.containerStatuses[?(@.name=="app")].resources}{"\n"}'

Tricks

Common mistakes

  • Using the wrong API group. VerticalPodAutoscaler is autoscaling.k8s.io/v1. The Horizontal Pod Autoscaler is autoscaling/v2. Mixing them gives no matches for kind.
  • Assuming VPA is there. no matches for kind "VerticalPodAutoscaler" or an unknown resource type vpa means the add-on is not installed. It is not a typo in your manifest.
  • Expecting the Deployment to change. VPA writes to Pods only. Compare the Pods, not the template.
  • Waiting for a single replica to be updated. With one live replica the updater does not evict by default. Scale to two, set updatePolicy.minReplicas: 1, or delete the Pod yourself so the webhook can do its part.
  • An empty recommendation. PROVIDED stays False when the VPA is new, when the Metrics Server is missing or broken (kubectl top pods fails too), or when targetRef names a workload that does not exist in that namespace.
  • Writing the mode in the wrong case, or unquoted. The values are "Off", "Initial", "Recreate" and "InPlaceOrRecreate". Unquoted Off is read by YAML as the boolean false and the object is rejected.
  • Running it beside a Horizontal Pod Autoscaler on CPU or memory. The two fight over the same signal.
  • Forgetting maxAllowed. A recommendation larger than any node leaves the replacement Pod Pending. A ceiling keeps the workload schedulable.

Recap

  • VPA changes how big Pods are (requests, and limits in proportion); the Horizontal Pod Autoscaler changes how many there are.
  • It is an add-on: VerticalPodAutoscaler in autoscaling.k8s.io/v1, with a recommender, an updater and an admission webhook, and it needs the Metrics Server.
  • The recommendation is in status.recommendation: target is what gets applied, between lowerBound and upperBound.
  • updateMode sets how far it goes: Off (advice), Initial (new Pods), Recreate (evict), InPlaceOrRecreate (resize, else evict). Auto is a deprecated alias of Recreate.
  • In the exam: kubectl get vpa, kubectl describe vpa, copy the manifest from the docs, and check the Pods, not the Deployment.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Practise: try it on a real cluster

A hands-on lab for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Section capstone. One Deployment, five jobs: get it past a broken init container, feed it from a ConfigMap and a Secret, add probes, release a new version with no gap, and prepare it for autoscaling.

    Fix · Level 3 · challenge · target 30 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.