CPU utilization
Ratio 1.7: outside the tolerance band 0.9–1.1.
- Ratio = 85% ÷ 50% = 1.7.
- Outside the tolerance band 0.9–1.1: ceil(1.7 × 4 pods) = ceil(6.8) = 7.
How many replicas will the HPA ask for, and why? The controller's exact math: tolerance, missing and unready pods, several metrics and behavior.
The form fills in as you paste; with status, current replicas and metric values come too.
One row per pod (current replicas, up to 30). Leave a value empty for a pod with no sample yet. Not ready: for CPU, a pod that is not Ready or still warming up; Pending: not running yet.
Describe how Metric 1's total demand changes; the timeline under the result shows how the HPA reacts. Each step holds until the next, and the ready pods share it: demand ÷ ready pods.
No steps: the load holds at today's value. Pick a preset or add a step.
New pods count as replicas at once, serve load after this.
--horizontal-pod-autoscaler-sync-period
Not set: the controller's built-in rules — up to max(2 × current, 4) replicas per sync on the way up, and the downscale stabilization flag on the way down.
Policies
Policies
--horizontal-pod-autoscaler-tolerance
--horizontal-pod-autoscaler-downscale-stabilization
Fix these to see the result:
Desired replicas
4 to 7
Scales up from 4 to 7 replicas — on the first sync.
Ratio 1.7: outside the tolerance band 0.9–1.1.
Sync by sync: 4 → 7 on the first sync, then it holds while the load does.
desiredReplicas = ceil(currentReplicas × currentMetric ÷ target). For example, 4 pods at 85% CPU against a 50% target give ceil(1.7 × 4) = 7.minReplicas and maxReplicas.kubectl get hpa NAME -o yaml, which fills in the spec and, from its status, the current values.kubectl get hpa shows them (cpu: 85%/50% is current 85, target 50).spec.behavior or your cluster runs non-default flags. The result shows the desired count, each metric's math and how the count moves sync by sync.For each metric the controller computes a ratio and multiplies it by the number of pods it counted:
desiredReplicas = ceil(currentReplicas × currentMetricValue ÷ desiredMetricValue)With 4 pods using 85% of their CPU request and a target of 50%: the ratio is 85 ÷ 50 = 1.7, outside the tolerance band, so the HPA asks for ceil(1.7 × 4) = ceil(6.8) = 7 replicas.
Two details matter at the edges. Utilization is a whole percentage computed before any division (Σusage × 100 ÷ Σrequests, rounded down), so 3 pods using 333m of 1 CPU each are at 33%, not 33.3%. And the product goes through a float64 math.Ceil, so a ratio that is a hair above a whole number adds a replica; the tool shows the exact product when that happens.
Nothing changes while the ratio is inside the band [1 − tolerance, 1 + tolerance], both edges included. The default tolerance of 0.1 is a kube-controller-manager flag, --horizontal-pod-autoscaler-tolerance. At a 50% target with 10 pods, 55% gives a ratio of 1.1 and keeps 10; 56% gives 1.12 and scales to 12.
Since Kubernetes 1.33 an HPA can set its own tolerance per direction, behavior.scaleUp.tolerance and behavior.scaleDown.tolerance, as a quantity such as 0.05. The HPAConfigurableTolerance feature gate was alpha in 1.33, beta and on by default in 1.35, and GA in 1.37. A direction you leave unset uses the flag.
The first pass uses only ready pods that have a sample. Pending pods are always set aside; for CPU, so are pods that are not Ready yet or still inside their CPU initialization period. Then, if any pod had no sample, or the ratio says scale up while pods were set aside, the controller re-checks with those pods filled in:
Each metric proposes a count and the largest wins: CPU at 48% against 60% keeps 4, a Pods metric at 90 per pod against 100 keeps 4, and an External queue of 900 against a Value target of 100 asks for 36, so the HPA goes to 36, or maxReplicas if lower. If a metric cannot be read, the HPA still scales up on the others but does not scale down on partial data.
Object and External metrics with an AverageValue target divide the metric's total by the current replicas: a total of 1,000 against 30 per pod with 4 replicas is ceil(1000 ÷ 30) = 34. With a Value target the ratio is multiplied by the number of ready pods. Container resource metrics work like resource metrics but use one container's usage and request.
The proposal is then kept within minReplicas and maxReplicas and rate-limited. What limits it depends on whether spec.behavior is set at all:
| spec.behavior not set | spec.behavior set (API defaults) | |
|---|---|---|
| Scale-up limit | max(2 × current, 4) per sync | larger of 4 pods and 100% per 15 s |
| Scale-up window | none | 0 s |
| Scale-down limit | none | 100% per 15 s |
| Scale-down window | 300 s (flag) | 300 s (flag), or stabilizationWindowSeconds |
| selectPolicy | — | Max |
The two columns are not the same: from 1 replica to a proposal of 40, without behavior the count goes 1 → 4 → 8 → 16 → 32 → 40; with behavior set to its defaults it goes 1 → 5 → 10 → 20 → 40, one sync every 15 seconds. A field you set replaces that field's default; the rest of the direction keeps its defaults.
Stabilization window: the controller remembers its recent recommendations. On the way down it uses the highest one inside the scaleDown window (its stabilizationWindowSeconds), so a drop from 10 to 3 replicas happens 300 seconds after the metric falls. On the way up it uses the lowest one inside the scaleUp window.
Policies: each policy allows a change of value pods or value% within periodSeconds, counted from where the count was at the start of the period. selectPolicy: Max takes the policy that allows the bigger change, Min the smaller, Disabled stops scaling in that direction.
When the workload has 0 replicas because someone scaled it to zero, the HPA computes nothing (ScalingActive=False). minReplicas: 0 needs an Object or External metric and the HPAScaleToZero feature gate (alpha since 1.16, beta and on by default in 1.37).
The timeline under the result runs the same controller code once per sync period (--horizontal-pod-autoscaler-sync-period, 15 s by default). Each step of the load profile sets Metric 1's total demand across all pods (CPU in cores for a CPU metric) and holds until the next step. At every sync the ready pods share it, so the metric is demand ÷ ready pods, and the controller compares that with the target through the tolerance band, the stabilization windows, the rate limits and min/max.
With the Spike preset on the default form (4 pods at 85% of a 500m request, target 50%), the HPA goes 4 → 7 at 0:00 and to maxReplicas 10 when the spike lands at 1:00. When the load falls back at 5:00 the metrics ask for 7, but the 300 s window still holds the higher recommendations from the spike: the first scale-down is at 9:45, to 7, and the count settles at 3. The shaded band on the chart is the window holding a scale-down.
Pods that start slowly. A pod the HPA adds counts toward replicas at once, because the controller divides by the pods that exist, but serves no load until it is ready. Set Pod ready after to model that: in the spike above, ready pods run above target for 4:15 with pods ready at once and for 5:00 with a 60 s start-up. For CPU, the controller sets pods that are not ready aside and, when it would scale up, re-checks counting them as using 0, which keeps it from adding pods while the new ones start (replica_calculator.go, groupPods). For other metrics a pod that is not ready is counted like any other; the model has it report 0, since it receives no traffic.
Flapping. With the load alternating between 15% above and 15% below target every minute (the Flapping preset), the HPA makes 2 scale events: it scales up at once, and the window absorbs every dip until the load stops changing. With the downscale window set to 0 the same load makes 8.
The engine is a line-by-line port of kube-controller-manager at release-1.37:
math.Ceil round the same way; sums of samples are exact integers like the controller's big.Int.replica_calculator_test.go (resource, tolerance, missing metrics, Pods, Object and External metrics) and of horizontal_test.go (scaling rules, stabilization, conversion with and without behavior). The load timeline is tested against controller steps computed by hand and against TestScaleUpHotCpuNoScale and TestStabilizeDownscale replayed as a timeline. A few vectors, recomputed at build time:| Upstream case | Input | Replicas |
|---|---|---|
| scale up | 3 pods at 300m, 500m, 700m of 1 CPU; target 30% | 5 |
| unready pod scales less | same, first pod not ready | 4 |
| scale down | 5 pods at 100m–500m, target 50% | 3 |
| missing pods scale down | 4 pods, 2 without samples, 400m and 95m, target 100% | 3 |
| re-check flips direction | 3 pods: unready 100m, 450m, one without a sample; target 50% | 3 |
| Pods metric, unready ignored | 50k, 10k, unready 30k; target 15k | 6 |
| External per pod | total 8.6 against 2.15 per pod, 3 replicas | 4 |
| Object, 1% scale-up tolerance | 20.666 against 20, 3 replicas | 4 |
desiredReplicas = ceil(currentReplicas × currentMetric ÷ target). With 4 pods at 85% CPU and a 50% target the ratio is 1.7, so ceil(1.7 × 4) = 7. Nothing changes while the ratio is within the tolerance (0.1 by default), and the result is kept within minReplicas and maxReplicas.
A dead band around the target: by default the HPA does not scale while the ratio is between 0.9 and 1.1. At a 50% target, 55% (ratio 1.1) changes nothing and 56% (ratio 1.12) scales 10 pods to 12. The default is a kube-controller-manager flag (horizontal-pod-autoscaler-tolerance); since Kubernetes 1.33 an HPA can set its own under behavior.scaleUp.tolerance and behavior.scaleDown.tolerance (HPAConfigurableTolerance: alpha in 1.33, beta and on by default in 1.35, GA in 1.37).
Scale-down waits for the stabilization window: the controller takes the highest recommendation of the last 300 seconds. If the metric drops so that 10 replicas should become 3, the first scale-down happens 300 seconds later. Without spec.behavior the window is a kube-controller-manager flag (the downscale stabilization window); with it, stabilizationWindowSeconds under behavior.scaleDown.
Without spec.behavior, to at most max(2 × current, 4) replicas per sync: 1 → 40 goes 1 → 4 → 8 → 16 → 32 → 40. Once behavior is set, the defaults are the larger of 100% and 4 pods per 15 seconds: 1 → 5 → 10 → 20 → 40. Each sync is 15 seconds apart by default.
Each metric proposes a replica count and the largest wins. CPU at 48% against 60% keeps 4, a Pods metric within tolerance keeps 4, and an External queue at 9 times its target asks for 36, so the HPA goes to 36 (or maxReplicas). If a metric cannot be read, the HPA still scales up on the others but never scales down.
Yes: under Load over time, describe Metric 1's total demand as steps (time → demand) or pick a preset. Each sync divides the demand by the ready pods and runs the controller's math. The Spike preset on the default form goes 4 → 7 → 10, and when the load drops at 5:00 the 300 s stabilization window holds 10 until 9:45. A readiness delay shows how long the ready pods run hot while new ones start.
The ratio is first computed from ready pods with samples. If it says scale up, pods without a sample count as using 0 and, for CPU, unready pods as 0 too; if it says scale down, pods without a sample count as using 100% of their request (or the target, if higher). If that re-check lands inside the tolerance or points the other way, nothing changes. Example: 3 pods at 300m, 500m and 700m of 1 CPU against 30% would go to 5, but with the first pod not ready it goes to 4.
Your input is processed in this browser tab and never sent to our servers. Privacy policy