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
Official competencies this lesson covers
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
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 Autoscaler | Vertical Pod Autoscaler | |
|---|---|---|
| Changes | spec.replicas of the workload | resources.requests (and limits) of the Pods |
| Reacts to | Current load against a target, within seconds to minutes | Usage history, over hours to days |
| API | autoscaling/v2, built into Kubernetes | autoscaling.k8s.io/v1, a custom resource from an add-on |
| Good for | Stateless services that can run many copies | Workloads that cannot simply add copies, or whose size nobody knows |
| Cost of a change | A Pod is added or removed | A 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:
| Field | Meaning | Default |
|---|---|---|
spec.targetRef | The workload to size: a Deployment, StatefulSet, DaemonSet or another controller. Not a bare Pod | required |
spec.updatePolicy.updateMode | How recommendations are applied: Off, Initial, Recreate, InPlaceOrRecreate | Recreate behaviour |
spec.updatePolicy.minReplicas | The fewest live replicas the workload must have before the updater may evict one | 2 (set on the updater) |
spec.resourcePolicy.containerPolicies[].containerName | The container the policy is for; "*" means every container without its own policy | none |
…minAllowed, …maxAllowed | Floor and ceiling for the recommendation | no bounds |
…controlledResources | Which resources VPA manages: cpu, memory or both | both |
…controlledValues | RequestsAndLimits or RequestsOnly | RequestsAndLimits |
…mode | Off leaves that one container alone, for example a sidecar | Auto |
What VPA works out appears in the object's status, as one entry per container with four values:
| Value | What it tells you |
|---|---|
target | The request VPA recommends. This is the number that is applied, and the one to copy if you set requests by hand |
lowerBound | Below this, the container is probably under-provisioned |
upperBound | Above this, the container is probably over-provisioned |
uncappedTarget | What the target would be without your minAllowed and maxAllowed. If it differs from target, your bounds are holding the recommendation back |
How it works
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.
- 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.recommendationof the VPA object. That is all it ever changes. - The updater looks at the running Pods of the target. If a Pod's requests are outside the range between
lowerBoundandupperBound, it is worth disturbing, so the updater evicts it (or resizes it in place, in the mode that allows that). - 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.
- 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
targetvalues before the Pod is stored. - 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 yamlstill 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
minAllowedandmaxAllowedwhen 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
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.
| Mode | New Pods get the target | Running Pods | Use it when |
|---|---|---|---|
Off | No | Never touched | You want advice only: read the target, then decide yourself. The safe first step |
Initial | Yes | Never touched | Restarts must happen on your schedule: values apply at the next rollout or scale-up |
Recreate | Yes | Evicted and replaced when too far from the recommendation | The workload has several replicas and tolerates restarts |
InPlaceOrRecreate | Yes | Resized without a restart where possible; evicted only when the resize cannot be done | You 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:
Autois the old name. It has been deprecated since VPA 1.4.0 and today behaves exactly likeRecreate. WriteRecreateorInPlaceOrRecreatein new manifests, but recogniseAutowhen you read one.InPlaceis 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.
VerticalPodAutoscalerisautoscaling.k8s.io/v1. The Horizontal Pod Autoscaler isautoscaling/v2. Mixing them givesno matches for kind. - Assuming VPA is there.
no matches for kind "VerticalPodAutoscaler"or an unknown resource typevpameans 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.
PROVIDEDstaysFalsewhen the VPA is new, when the Metrics Server is missing or broken (kubectl top podsfails too), or whentargetRefnames 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". UnquotedOffis read by YAML as the booleanfalseand 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 PodPending. 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:
VerticalPodAutoscalerinautoscaling.k8s.io/v1, with a recommender, an updater and an admission webhook, and it needs the Metrics Server. - The recommendation is in
status.recommendation:targetis what gets applied, betweenlowerBoundandupperBound. updateModesets how far it goes:Off(advice),Initial(new Pods),Recreate(evict),InPlaceOrRecreate(resize, else evict).Autois a deprecated alias ofRecreate.- 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.