HPA changes the count; VPA changes the size
Pod api-1 of the api Service runs with the CPU and memory requests (the amount of resources a pod reserves as its minimum need) set at the start.
HPA (Horizontal Pod Autoscaler) adds and removes pods. VPA (Vertical Pod Autoscaler) instead adjusts the CPU and memory given to each pod.
Key ideaThis is different from cluster autoscaling, which adds nodes. That handles the number of servers; HPA and VPA handle the number and size of pods running on them.
Create a VPA rule and attach it to a workload
VPA is not part of the default install, so you install it separately. Create a VerticalPodAutoscaler object and pick the target workload, such as a Deployment, StatefulSet, or DaemonSet, with targetRef.
Also set the update mode (updateMode) and the min and max CPU and memory range (minAllowed, maxAllowed). Start in recommend-only mode (Off).
Key ideaSet maxAllowed at or below the target workload's limits. If you set it higher, automatic adjustment can fail.
What changed in this step
- +Create VPA (target: Deployment)
Collect what the pods actually used
Metrics Server collects CPU and memory usage for pods and nodes. HPA gets its CPU and memory metrics from the same place.
The VPA Recommender (the part that computes recommendations) watches this usage over time. It looks at accumulated history, not a single moment.
The Recommender computes the right size
From the collected history, the Recommender computes suitable CPU and memory requests for this pod. The result is attached to the VPA rule as a recommendation.
Recommendations stay within the min and max range set on the VPA.
In recommend-only mode, pods stay as they are
In recommend-only mode, VPA just computes recommendations and leaves pods alone. Use it to check whether the current values are reasonable first.
To apply them to real pods, switch the update mode to an applying mode (Recreate, Auto). Check the current mode in updatePolicy.updateMode in the VPA YAML.
In apply mode, pods are recreated with new values
Switch the update mode to apply, and the VPA Updater (the part that applies changes) evicts pods whose values are far from the recommendation. It usually does not resize running pods in place; it changes them by recreating the pods.
The workload creates a new pod, api-2, to fill the gap, and the new pod gets the recommendation as its requests.
Key ideaRecreating pods causes a brief restart. If a Service has only one pod, no pod is there to take requests in the meantime.
What changed in this step
- ~Update mode: Recommend only → Apply
- −api-1 terminated
- +api-2 created (recommendation applied)
The workload YAML values stay the same
VPA does not edit the resource values in the workload spec (YAML). Only the values on running pods change.
So the Deployment YAML alone does not tell you what the pods have right now. Use kubectl get pod -o yaml for the pod's actual requests and kubectl describe vpa for the recommendation.
Watch out"I never changed the YAML, but the pod values are different" usually means a VPA is attached.
HPA and VPA can clash if they watch the same metric
If HPA changes the pod count based on CPU while VPA changes pod size based on the same CPU, the two adjustments affect each other. One adds pods while the other shrinks them, for example.
Kubernetes does not stop you from using both. But avoid having both adjust the same CPU or memory. Drive HPA with a different metric, or keep VPA in recommend-only mode.
VPA changes the size; check it on the pod
VPA computes recommendations from usage history, and in apply mode it recreates pods with those values. The workload YAML stays the same.
So check actual values on the running pods, not the spec. When using it with HPA, make sure they do not watch the same metric.
SummaryVPA changes pod size, not pod count. It derives recommendations from usage history and, in apply mode, recreates pods with them. If the spec and actual pod values differ, suspect VPA first.