Practical technical guides / Core IT: Kubernetes

Work Out When a Kubernetes HPA Will Scale Down: Tolerance, Stabilization Window and Rate Policies

Compute an autoscaling/v2 HPA scale-down from the v1.37.3 controller rules: the 10 percent tolerance, the five-minute window and rate policies, three timelines.

By Sandeep Belgavi · Published 2026-11-27

Compute an autoscaling/v2 HPA scale-down from the v1.37.3 controller rules: the 10 percent tolerance, the five-minute window and rate policies, three timelines.

Why scale-down timing surprises people

Traffic to the catalogue search service of Belgavi's Book Store falls by three quarters at the end of an evening sale. The HorizontalPodAutoscaler targets 60 percent CPU, the service runs 20 replicas, and the load now needs about 5. Some teams expect the replica count to drop within a minute. Others are surprised that it drops all at once five minutes later, taking warm caches with it. Both reactions come from not working out the numbers in advance.

The autoscaling/v2 API gives you four controls that decide the timeline: the tolerance, the stabilization window, the scaling policies and selectPolicy. Each is simple; together they interact. This guide works through the arithmetic the controller performs, using the Kubernetes v1.37.3 controller source as the reference, and shows three scale-down configurations side by side. The numbers come from a calculation in the companion example, not from a cluster run.

Step 1: the raw recommendation and the tolerance

On each sync, every 15 seconds by default, the controller computes a desired replica count from the ratio of the current metric to the target:

desiredReplicas = ceil(currentReplicas * currentMetricValue / desiredMetricValue)

Before using it, the controller checks the ratio against the tolerance. In replica_calculator.go, the check is (1.0 - scaleDownTolerance) <= ratio <= (1.0 + scaleUpTolerance); inside that band the recommendation is the current replica count. The default tolerance is 0.1 for both directions, set cluster-wide by the kube-controller-manager flag --horizontal-pod-autoscaler-tolerance.

So with a 60 percent target, utilization between 54 and 66 percent causes no change. In the companion example, 20 replicas at 64 percent produce a ratio of 1.067 and stay at 20 on every sync.

Since Kubernetes 1.37 you can set the tolerance per direction in the HPA itself. The HPAConfigurableTolerance feature gate was alpha in 1.33 and 1.34, beta but off by default in 1.35 and 1.36, and is stable and locked on from 1.37. A tighter scale-up tolerance makes the HPA react to smaller rises; a looser scale-down tolerance keeps it from shrinking on small dips.

Step 2: the stabilization window

The controller keeps every raw recommendation it computes, with a timestamp. When the current recommendation is lower than the current replica count, it does not use it directly. In stabilizeRecommendationWithBehaviors, it takes the highest recommendation recorded inside the scale-down window, and in the scale-up direction the lowest inside the scale-up window. The documentation describes the scale-down case as an approximate rolling maximum.

The default scale-down window is 300 seconds, or the value of the --horizontal-pod-autoscaler-downscale-stabilization flag. The default scale-up window is 0, so increases apply at once.

For the sale example, this is the whole explanation of the five-minute delay. For 300 seconds after the drop, some recommendation from before the drop, when the service needed 20, is still inside the window, so the stabilized recommendation stays 20. In the 15-second model the window releases at 285 seconds; the controller compares timestamps strictly, and the last pre-drop sample falls out of the window then. On a real cluster expect about five minutes, give or take a sync.

Step 3: the rate policies

Once a stabilized recommendation differs from the current count, the policies limit how far one step may go. Each policy has a type (Pods or Percent), a value and a periodSeconds. The controller computes, for each policy, the replica count at the start of the period, which is the current count adjusted by every scale event recorded within the last periodSeconds, and then the limit that policy allows:

// From calculateScaleDownLimitWithBehaviors, Kubernetes v1.37.3
periodStartReplicas := currentReplicas - replicasAddedInCurrentPeriod + replicasDeletedInCurrentPeriod
if policy.Type == autoscalingv2.PodsScalingPolicy {
    proposed = periodStartReplicas - policy.Value
} else if policy.Type == autoscalingv2.PercentScalingPolicy {
    proposed = int32(float64(periodStartReplicas) * (1 - float64(policy.Value)/100))
}

Three details follow from the code. Percent limits for scale-down are truncated toward zero, so 10 percent of 72 replicas allows going to 64, a step of 8, which matches the example in the documentation. For scale-up, percent limits are rounded up, so a small deployment can always grow by at least one. And scale events within the period count against the limit, so a policy of 2 pods per 60 seconds really means 2 pods per rolling minute, not 2 pods per sync.

With several policies, selectPolicy: Max, the default, picks the policy that allows the largest change; Min picks the smallest; Disabled turns off scaling in that direction. The default scale-down behaviour has a single policy, 100 percent per 15 seconds, which is why it drops straight to the target once the window releases. The default scale-up behaviour allows the larger of 100 percent or 4 pods per 15 seconds.

Three scale-down timelines

The companion example hpa_behavior_model replays the controller every 15 seconds, with ten minutes of history before the drop so the window is full. Demand falls from 1200 to 300 pod-percent at t=0, the target is 60 percent, the minimum is 2 and the maximum 30.

Scale-down behaviorFirst removalReaches 5 replicasSteps
Defaults: window 300 s, 100% per 15 s285 s285 s20 to 5 in one step
Window 60 s, 2 pods per 60 s45 s465 s20, 18, 16, 14, 12, 10, 8, 6, 5
Window 120 s, 25% per 60 s105 s345 s20, 15, 11, 8, 6, 5

The second configuration starts shrinking almost immediately but takes almost eight minutes, which is gentle on caches and connection pools but keeps paying for idle replicas. The third is a compromise: it waits two minutes in case the drop is a blip, then removes a quarter per minute, which takes larger steps while the deployment is large and smaller ones near the end. The YAML for that row is:

# Author: Sandeep Belgavi. Catalogue search: wait two minutes, then shrink by a quarter per minute.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: catalogue-search
spec:
  scaleTargetRef: {apiVersion: apps/v1, kind: Deployment, name: catalogue-search}
  minReplicas: 2
  maxReplicas: 30
  metrics:
  - type: Resource
    resource: {name: cpu, target: {type: Utilization, averageUtilization: 60}}
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 120
      policies:
      - {type: Percent, value: 25, periodSeconds: 60}

Fields you leave out are merged with the defaults, so this HPA keeps the default scale-up behaviour.

Choosing the numbers

Work backwards from what a removal costs. If a new replica needs 90 seconds to warm its cache, a stabilization window shorter than the typical gap between traffic bursts will remove replicas you need again soon. Look at a week of the metric and measure how long dips last before traffic returns; set the window longer than most of them.

Then choose the rate from what the rest of the system tolerates. Removing 15 replicas in one step drains 15 sets of connections at once; databases and downstream services may see a reconnect storm when traffic returns. A percent policy scales the step with the deployment, and a pods policy caps it in absolute terms. Combining the two with selectPolicy: Min gives you the smaller of both, which suits services whose dependencies are the real limit.

Finally, check the tolerance against the metric's natural noise. If CPU wanders between 55 and 65 percent under steady load, the default 10 percent band is about right; a tighter band makes the HPA chase noise.

What the model leaves out

The real controller also handles Pods that are not ready, missing metrics and CPU initialization; it treats missing Pods as using 100 percent of their request on a scale-down and 0 percent on a scale-up, and can skip scaling when that changes the direction. It also depends on metric collection delay and on the actual sync timing. Use the model to compare configurations and to explain a timeline, and confirm the chosen behaviour on a staging cluster with kubectl describe hpa, whose conditions report ScaleDownStabilized and ScaleDownLimit when the window or a policy holds the count back.

Limits of this guide

The algorithm, defaults and feature-gate stages come from the Kubernetes documentation and the v1.37.3 controller source. The timelines are calculations from the companion example, not measurements on a cluster, and the exact seconds depend on the 15-second sync assumption.

Primary references and authorship

Sources checked 2026-11-27. Original explanation and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/hpa_behavior_model. Views are my own and do not represent any employer, past or present.