Set stabilization windows and scaling policies in the behavior field to control pod scaling speed.
Prerequisites
Make sure you have:
-
An ACK cluster running Kubernetes 1.24 or later. See Manually update ACK clusters
-
HPA enabled in the cluster. See Implement horizontal pod autoscaling
-
A kubectl client configured with
autoscaling/v2or later
Choose a scaling scenario
Find the configuration that matches your workload.
| Goal | Scenario | Scale-out speed | Scale-in speed |
|---|---|---|---|
| Handle sudden traffic spikes | Rapid scale-out | Very fast (900% growth every 15 s) | Default |
| Scale out fast, scale in slowly | Balanced scaling | Fast (900% growth every 60 s) | Slow (1 pod every 10 min) |
| Never remove pods automatically | Disable scale-in | Moderate (100% growth every 60 s) | Disabled |
| Minimize cost, avoid over-provisioning | Cost-optimized | Slow (50% or 2 pods every 2 min) | Slow (25% or 3 pods every 10 min) |
| Adapt to unpredictable traffic | Adaptive scaling | Moderate (50% or 4 pods every 60 s) | Slow (20% or 2 pods every 5 min) |
Default HPA behavior
When no behavior section is specified, Kubernetes applies the following defaults:
behavior:
scaleUp:
stabilizationWindowSeconds: 0 # Scale out immediately
policies:
- type: Percent
value: 100 # Double the current pod count
periodSeconds: 15
- type: Pods
value: 4 # Or add 4 pods
periodSeconds: 15
selectPolicy: Max # Use whichever adds more pods
scaleDown:
stabilizationWindowSeconds: 300 # Wait 5 minutes before scaling in
policies:
- type: Percent
value: 100 # Remove up to 100% of pods
periodSeconds: 15
selectPolicy: Max
With these defaults:
-
Scale-out happens immediately. Every 15 seconds, the controller can double the pod count or add 4 pods, whichever is greater.
-
Scale-in waits 5 minutes. The controller selects the highest recommended replica count from the past 300 seconds to avoid premature removal.
Specify only fields that differ — Kubernetes merges your values with the defaults.
Field reference
All fields in the behavior section:
| Field | Type | Range | Default (scaleUp) |
Default (scaleDown) |
Description |
|---|---|---|---|---|---|
stabilizationWindowSeconds |
int32 | 0–3600 | 0 | 300 | Lookback window (seconds) for scaling recommendations. The controller picks the highest replica count (scaleDown) or the lowest (scaleUp) within this window. Set to 0 for immediate scaling. |
policies |
array | 1 or more entries | See above | See above | One or more scaling policies. Each policy specifies a type, value, and periodSeconds. |
policies[].type |
string | Pods or Percent |
-- | -- | Whether the value represents an absolute pod count or a percentage of current replicas. |
policies[].value |
int32 | > 0 | -- | -- | Number of pods or percentage of current replicas to add or remove per period. |
policies[].periodSeconds |
int32 | 1–1800 | 15 | 15 | Time interval (seconds) over which the policy value applies. |
selectPolicy |
string | Max, Min, Disabled |
Max |
Max |
Which policy to use when multiple policies exist. Max: changes the most pods (aggressive). Min: changes the fewest pods (conservative). Disabled: prevents all scaling in that direction. |
Complete HPA configuration example
A complete HPA resource with a custom behavior section. Modify fields as needed.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: optimized-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: web-application
minReplicas: 2
maxReplicas: 50
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Pods
value: 5
periodSeconds: 60
- type: Percent
value: 10
periodSeconds: 60
selectPolicy: Min
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Percent
value: 100
periodSeconds: 15
- type: Pods
value: 4
periodSeconds: 15
selectPolicy: Max
In this example:
-
scaleDownuses a 300-second stabilization window. Two policies — remove up to 5 pods or 10% every 60 seconds — are evaluated, andselectPolicy: Minpicks whichever removes fewer. -
scaleUpresponds immediately (stabilizationWindowSeconds: 0). Two policies — double the pod count or add 4 pods every 15 seconds — are evaluated, andselectPolicy: Maxpicks whichever adds more.
Scenario configurations
Rapid scale-out for burst workloads
For sudden traffic spikes such as flash sales, product launches, or promotional campaigns.
behavior:
scaleUp:
policies:
- type: Percent
value: 900 # Increase the current pod count by 900%
periodSeconds: 15
How it works: Every 15 seconds, the controller attempts to add 900% of the current pod count, which scales the workload out to 10x its current replicas.
Scaling progression from 1 replica:
1 -> 10 -> 100 -> 1000
The final count is capped at maxReplicas.
Balanced scaling with conservative scale-in
Scale out fast to handle traffic increases and scale in slowly to prevent premature pod removal.
behavior:
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Percent
value: 900 # 10x the current pod count
periodSeconds: 60
selectPolicy: Max
scaleDown:
stabilizationWindowSeconds: 600 # 10-minute evaluation window
policies:
- type: Pods
value: 1
periodSeconds: 600 # Remove 1 pod every 10 minutes
selectPolicy: Min
How it works:
-
Scale-out: Immediate. Every 60 seconds, the pod count can grow by up to 900% of the current count.
-
Scale-in: Metrics must stay low for 10 minutes before scale-in. Then only 1 pod is removed every 10 minutes.
Scale-in walkthrough from 20 replicas:
| Time | Action | Pod count |
|---|---|---|
| 0:00 | Metrics drop below target | 20 (stabilization window starts) |
| 0:00–10:00 | Controller collects recommendations but takes no action | 20 |
| 10:00 | Stabilization window passes. Remove 1 pod | 19 |
| 20:00 | Remove 1 pod | 18 |
| 30:00 | Remove 1 pod | 17 |
Disable scale-in for critical applications
For stateful applications, batch jobs, or services handling long-running transactions where scale-in could disrupt operations.
behavior:
scaleDown:
selectPolicy: Disabled # Completely disable scale-in
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Percent
value: 100
periodSeconds: 60
selectPolicy: Max
How it works: selectPolicy: Disabled on scaleDown prevents pod removal. The workload grows but never shrinks automatically. Scale-out doubles the pod count every 60 seconds, after a 60-second stabilization delay.
To scale in manually, delete the HPA and runkubectl scaleto set the desired replica count, or temporarily changeselectPolicyto allow automatic scale-in.
Cost-optimized scaling with controlled growth
Prevent over-provisioning during short-lived spikes and reduce capacity only after sustained low demand.
behavior:
scaleUp:
stabilizationWindowSeconds: 120 # Wait 2 minutes before scaling out
policies:
- type: Percent
value: 50 # 50% growth
periodSeconds: 120
- type: Pods
value: 2 # Or add 2 pods
periodSeconds: 120
selectPolicy: Min # Use whichever adds fewer pods
scaleDown:
stabilizationWindowSeconds: 900 # 15-minute evaluation window
policies:
- type: Percent
value: 25 # Remove 25% of pods
periodSeconds: 600
- type: Pods
value: 3 # Or remove 3 pods
periodSeconds: 600
selectPolicy: Min
How it works:
-
Scale-out: A 2-minute stabilization window filters transient spikes.
selectPolicy: Minadds the smaller of 50% or 2 pods every 2 minutes, limiting waste. -
Scale-in: A 15-minute evaluation window ensures sustained low demand before removal. Removes at most 25% or 3 pods (whichever fewer) every 10 minutes.
Scale-out walkthrough from 4 replicas:
| Step | Current pods | Percent policy (50%) | Pods policy (+2) | Selected (Min) | New pod count |
|---|---|---|---|---|---|
| 1 | 4 | 50% of 4 = 2 | 2 | 2 | 6 |
| 2 | 6 | 50% of 6 = 3 | 2 | 2 | 8 |
| 3 | 8 | 50% of 8 = 4 | 2 | 2 | 10 |
With selectPolicy: Min, the Pods policy caps growth at 2 pods per period until the percentage calculation falls below 2.
Adaptive scaling for unpredictable workloads
Handle variable traffic patterns with responsive scale-out and cautious scale-in.
behavior:
scaleUp:
stabilizationWindowSeconds: 30
policies:
- type: Pods
value: 4
periodSeconds: 60
- type: Percent
value: 50
periodSeconds: 60
selectPolicy: Max # Use whichever adds more pods
scaleDown:
stabilizationWindowSeconds: 600
policies:
- type: Pods
value: 2
periodSeconds: 300
- type: Percent
value: 20
periodSeconds: 300
selectPolicy: Min # Use whichever removes fewer pods
How it works:
-
Scale-out: After a 30-second stabilization delay, the controller adds 4 pods or 50% of the current count (whichever is greater) every 60 seconds. Asymmetric
selectPolicy—Maxfor scale-out,Minfor scale-in — drives aggressive growth and conservative reduction. -
Scale-in: Requires 10 minutes of sustained low metrics. Then removes 2 pods or 20% of current pods (whichever is fewer) every 5 minutes.
Monitor HPA behavior
Inspect HPA status and scaling events:
# View current HPA status and recent scaling events
kubectl describe hpa <hpa-name>
# Monitor HPA metrics and decisions
kubectl get hpa <hpa-name> -o yaml
# Check pod resource usage
kubectl top pods -l <label-selector>
Expected output from kubectl describe hpa:
Name: optimized-hpa
Namespace: default
Metrics: ( current / target )
resource cpu on pods (as a percentage of request): 35% (175m) / 70%
Min replicas: 2
Max replicas: 50
Behavior:
Scale Up:
Stabilization Window: 0 seconds
Select Policy: Max
Policies:
- Type: Percent Value: 100 Period: 15 seconds
- Type: Pods Value: 4 Period: 15 seconds
Scale Down:
Stabilization Window: 300 seconds
Select Policy: Min
Policies:
- Type: Pods Value: 5 Period: 60 seconds
- Type: Percent Value: 10 Period: 60 seconds
Deployment pods: 4 current / 4 desired
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulRescale 12m horizontal-pod-autoscaler New size: 4; reason: cpu resource utilization (percentage of request) above target
Check Events for scaling decisions and Behavior to confirm policies are applied.
Apply in production
Test in staging first
-
Simulate realistic load patterns in staging before applying to production.
-
Validate that chosen metrics accurately reflect your application's performance.
-
Test edge cases including rapid traffic spikes and sustained low utilization.
Plan for Cluster Autoscaler delays
When HPA scales out rapidly, the cluster may lack node capacity. The Cluster Autoscaler provisions new nodes for unschedulable pods, but this takes 1–3 minutes. Factor this delay into your expectations. See Node scaling.
Combine with other autoscaling strategies
-
Use Vertical Pod Autoscaler (VPA) alongside HPA for workloads that need both horizontal and vertical scaling.
-
Use custom metrics and external adapters for scaling beyond CPU and memory.
References
-
If you encounter issues when you use HPA, see Workload scaling FAQ.