Skip to content

Commit 05db117

Browse files
authored
Merge pull request #50558 from jayeshmahajan/patch-6
Add more clarity for horizontal-pod-autoscaler-cpu-initialization-period
2 parents 227f9ed + b1af125 commit 05db117

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

content/en/docs/tasks/run-application/horizontal-pod-autoscale.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,38 @@ highest recommendation from within that window. This value can be configured usi
217217
This means that scaledowns will occur gradually, smoothing out the impact of rapidly
218218
fluctuating metric values.
219219

220+
### Pod readiness and autoscaling metrics
221+
222+
The HorizontalPodAutoscaler (HPA) controller includes two flags that influence how CPU metrics are collected from Pods during startup:
223+
224+
1. `--horizontal-pod-autoscaler-cpu-initialization-period` (default: 5 minutes)
225+
226+
This defines the time window after a Pod starts during which its **CPU usage is ignored** unless:
227+
- The Pod is in a `Ready` state **and**
228+
- The metric sample was taken entirely during the period it was `Ready`.
229+
230+
This flag helps **exclude misleading high CPU usage** from initializing Pods (e.g., Java apps warming up) in HPA scaling decisions.
231+
232+
2. `--horizontal-pod-autoscaler-initial-readiness-delay` (default: 30 seconds)
233+
234+
This defines a short delay period after a Pod starts during which the HPA controller treats Pods that are currently `Unready` as still initializing, **even if they have previously transitioned to `Ready` briefly**.
235+
236+
It is designed to:
237+
- Avoid including Pods that rapidly fluctuate between `Ready` and `Unready` during startup.
238+
- Ensure stability in the initial readiness signal before HPA considers their metrics valid.
239+
240+
**Key behaviors:**
241+
- If a Pod is `Ready` and remains `Ready`, it can be counted as contributing metrics even within the delay.
242+
- If a Pod rapidly toggles between `Ready` and `Unready`, metrics are ignored until it’s considered stably `Ready`.
243+
244+
#### Best Practice:
245+
If your Pod has a startup phase with high CPU usage, configure both:
246+
- `--horizontal-pod-autoscaler-cpu-initialization-period` to **cover the startup duration**.
247+
- Ensure your **readinessProbe** only reports `Ready` **after the CPU spike subsides**, using `initialDelaySeconds`.
248+
249+
This avoids scaling based on temporary spikes that do not reflect long-term workload needs.
250+
251+
220252
## API Object
221253

222254
The Horizontal Pod Autoscaler is an API resource in the Kubernetes

0 commit comments

Comments
 (0)