Skip to main content

VPA and capacity planning

Stage 7 · Orbital Maneuvering

You will be able to: read a VPA recommendation and say how it was computed, choose an update mode and know which VPA component each one needs, explain the HPA/VPA feedback loop and the safe ways to combine them, apply a recommendation without side effects, and reason about where scaling stops: at node capacity.

Every request in Apollo is a guess made in Stage 4: 100m and 128Mi for the default tier, 200m and 256Mi for booking. Those guesses now matter more than ever. The scheduler packs nodes by them, QoS ranks evictions by them, and the HPA divides by them (Horizontal Pod Autoscaling). Too high, and capacity is wasted and the HPA scales in too eagerly. Too low, and Pods are throttled or OOM-killed and the HPA overreacts. A measured suggestion is better than a guess.

The Vertical Pod Autoscaler​

The HPA changes how many Pods run. The Vertical Pod Autoscaler (VPA) works out how big each Pod's requests should be. It is an add-on from the Kubernetes autoscaler project, with three components:

ComponentDoesApollo
RecommenderReads usage from metrics.k8s.io, keeps a history per container, writes recommendations into each VPA object's statusInstalled (v1.7.0)
UpdaterIn modes that apply changes, evicts Pods whose requests are far from the recommendationInstalled; does nothing for an Off VPA
Admission controllerA mutating webhook that rewrites requests on new Pods as they are createdOmitted: Off mode never mutates Pods, so a TLS webhook would only add a failure mode

A VerticalPodAutoscaler object names a target and a policy:

# search-vpa.yaml (trimmed)
spec:
targetRef: {apiVersion: apps/v1, kind: Deployment, name: search}
updatePolicy:
updateMode: "Off" # recommend only
resourcePolicy:
containerPolicies:
- containerName: search
minAllowed: {cpu: 50m, memory: 64Mi}
maxAllowed: {cpu: 1, memory: 512Mi}
controlledResources: ["cpu", "memory"]

How a recommendation is computed​

The recommender samples each container's CPU and memory use and keeps them in decaying histograms: recent samples weigh more, with a half-life of about a day by default. History is saved in VerticalPodAutoscalerCheckpoint objects, so it survives a recommender restart.

FieldRoughly (defaults)Use it as
lowerBoundA low percentile of usageBelow this, the Pod is likely starved
targetAbout the 90th percentile of CPU and of memory peaks, plus a 15% safety marginThe suggested request
upperBoundA high percentileAbove this, the request is likely wasted
uncappedTargetThe target before minAllowed/maxAllowedShows when your policy bounds are clipping the advice

Three behaviours matter when reading one:

  • Bounds are wide while history is short. The less data, the further apart lower and upper bounds are. Recommendations stay empty until enough samples exist. A ten-minute lab gives a hint, not a sizing.
  • Memory is sized for peaks. An OOM kill bumps the memory recommendation up sharply.
  • There are floors. By default the recommender does not go below about 25m CPU and 250 Mi of memory per Pod, so a small service is often recommended more memory than it uses. Check uncappedTarget against observed usage before accepting it.

The recommendation is only as representative as the traffic it saw. A week of quiet nights and one sales event produce a different answer than a load test.

Update modes​

ModeBehaviourNeedsRisk
Off (Apollo)Recommend onlyRecommenderNone
InitialApply only when a Pod is createdRecommender + admission controllerLow: changes arrive with normal rollouts
Recreate / AutoEvict running Pods to recreate them with new requestsAll threeRestarts; fights the HPA on CPU; eviction respects PDBs but still disrupts single-replica workloads

When the VPA does apply changes, it scales limits proportionally with requests by default, so a Guaranteed Pod stays Guaranteed.

Why the HPA and VPA fight over CPU​

Both use the CPU request: the HPA divides by it, an active VPA rewrites it.

Each controller's action changes the other's input. The result oscillates instead of settling. Safe combinations:

HPA scales onVPASafe?
CPUOff, a person applies advice (Apollo)Yes
CPUActive on memory only (controlledResources: [memory])Yes
A custom metric (requests/s, queue length)Active on CPU and memoryYes
CPUActive on CPUNo

Applying a recommendation​

A person reads the advice, changes the chart, and ships it through Helm or Argo CD (Stage 5), so the change is reviewed and in Git. Two traps sit in Apollo's chart:

  • Tiers are shared. Search uses the default tier, and so does flight. The VPA template's own comment suggests updating tiers.default; doing that resizes flight too, on advice measured only from search. Give search its own tier (or an override) first.
  • The HPA's denominator moves. Raising search's CPU request from 100m to 150m means the same load now reads as two-thirds the utilization, so the HPA settles on fewer replicas. Rerun the same load afterwards and compare p95, throttling and replica counts (Measurement before optimization).

Capacity is the real limit​

Neither autoscaler creates hardware. The HPA asks for Pods, the VPA asks for bigger Pods, and the scheduler must find room for their requests (Scheduling).

On Apollo's kind cluster, two workers are all there is. The airline already books about 1.9 CPUs before any scaling (Stage 4's totals), plus the observability stack. Search at maxReplicas: 10 would ask for another 1 CPU on top.

In the cloud, a cluster autoscaler (Stage 9, planned) watches for Pods that are Pending because nothing fits, and adds nodes; it removes nodes whose Pods fit elsewhere. Three things it does not change:

  • It is slow. A new node takes minutes to boot and join; the HPA reacts in seconds. Teams often keep spare room with low-priority placeholder Pods, which real Pods preempt instantly while the new node boots.
  • It cannot satisfy impossible Pods. A Pod with an unsatisfiable affinity, a volume pinned to one zone, or a request larger than any node type stays Pending.
  • It is bounded too. Node-group maximums, quotas and budgets cap it.

Apollo example​

Settingdevstaging, prod
VPA for searchDisabledEnabled, Off
ComponentsnoneRecommender + updater in kube-system; no admission controller
Policy50m–1 CPU, 64Mi–512Mi, CPU and memory
metrics-serverBundledBundled

Try it​

Unverified

Not yet run on a live cluster for this documentation revision. Needs Stage 7 installed with --env staging (dev disables the VPA) and some traffic; recommendations appear only after enough samples.

NS=apollo-airlines-apps
kubectl get deploy -n kube-system | grep vpa # recommender, updater; no admission controller
kubectl -n $NS get vpa search-vpa # MODE Off
kubectl -n $NS get vpa search-vpa -o jsonpath='{.status.recommendation.containerRecommendations[0]}' | jq .
kubectl -n $NS get deploy search -o jsonpath='{.spec.template.spec.containers[0].resources}'; echo
kubectl top pods -n $NS -l app=search # actual usage now
kubectl -n $NS get verticalpodautoscalercheckpoints # the stored history
kubectl get events -n $NS --field-selector reason=EvictedByVPA # none in Off mode
  • Compare target with the current request and with kubectl top. A wide gap between lowerBound and upperBound means the history is still short.
  • If target and uncappedTarget differ, the policy's min or max is clipping the advice.
  • No evictions: Off only writes status.

Common misconceptions​

  • "The VPA resizes my Pods." Not in Off mode, and not at all without the admission controller.
  • "A recommendation is a measurement." It is a percentile of the history it saw, plus a margin and floors.
  • "Running an HPA and a VPA together is always wrong." It is wrong when both act on CPU.
  • "Autoscaling means unlimited capacity." Pods still need room on real nodes.
  • "Updating the tier only affects search." Flight shares it.

Check yourself​

Why does Apollo run the VPA in Off mode beside a CPU-based HPA?

An active VPA would rewrite the CPU request that the HPA divides by, and the two would chase each other. Off gives sizing advice without touching Pods.

The VPA recommends 250Mi of memory for search, which uses 40Mi. Why might that be, and what do you check?

The recommender has a default per-Pod memory floor and adds safety margins. Compare uncappedTarget, lowerBound and actual usage before accepting it.

You raise search's CPU request from 100m to 150m. What happens to its HPA under the same load?

Utilization drops to two-thirds of its previous value, so the HPA settles on fewer replicas. Rerun the load to compare.

The HPA wants 8 search Pods and 3 are Pending. Which autoscaler can help?

Neither the HPA nor the VPA. Room must come from freeing requests or adding nodes, which a cluster autoscaler does in the cloud, over minutes.

Where this leads​

That completes the local path: Apollo runs, survives, ships, can be observed and scales. The planned missions continue with Stage 8: securing what is now running.

References​