HPA

3 min read

Read a HorizontalPodAutoscaler: current, desired, minimum and maximum replicas, whether it is scaling or at its limit, its conditions, its scale target and the types of metric it reports.

Reference

FunctionDescription
hpaAbleToScaleReturns true when the AbleToScale condition is True — the scale target exists and is reachable.
hpaAtMaxReturns true when currentReplicas >= maxReplicas — the HPA has hit its ceiling.
hpaCurrentReplicasReturns status.currentReplicas as int64.
hpaDesiredReplicasReturns status.desiredReplicas as int64.
hpaMaxReplicasReturns spec.maxReplicas as int64.
hpaMetricTypesReturns the type of each metric the HPA currently reports (status.currentMetrics): Resource, Pods, Object, External, ContainerResource.
hpaMinReplicasReturns spec.minReplicas as int64, defaulting to 1 when not set (matching the Kubernetes default).
hpaScaleTargetKindReturns the kind of the workload the HPA scales (spec.scaleTargetRef.kind).
hpaScaleTargetNameReturns the name of the workload the HPA scales (spec.scaleTargetRef.name).
hpaScalingReturns true when the HPA has a valid metric (ScalingActive=True) and currentReplicas != desiredReplicas — a real scale-out or scale-in is in progress.
hpaScalingActiveReturns true when the ScalingActive condition is True — the HPA can read its metric and is permitted to scale.
hpaScalingLimitedReturns true when the ScalingLimited condition is True — the desired replica count was clamped by the min or max bound.

Functions

hpaAbleToScale

hpaAbleToScale returns true when the AbleToScale condition is True — the scale target exists and is reachable.

{{ hpaAbleToScale .hpa }}  → true

hpaAtMax

hpaAtMax returns true when currentReplicas >= maxReplicas — the HPA has hit its ceiling.

{{ hpaAtMax .hpa }}  → false

hpaCurrentReplicas

hpaCurrentReplicas returns status.currentReplicas as int64.

{{ hpaCurrentReplicas .hpa }}  → 3

hpaDesiredReplicas

hpaDesiredReplicas returns status.desiredReplicas as int64.

{{ hpaDesiredReplicas .hpa }}  → 5

hpaMaxReplicas

hpaMaxReplicas returns spec.maxReplicas as int64.

{{ hpaMaxReplicas .hpa }}  → 10

hpaMetricTypes

hpaMetricTypes returns the type of each metric the HPA currently reports (status.currentMetrics): Resource, Pods, Object, External, ContainerResource.

{{ hpaMetricTypes .hpa }}  → [Resource External]

hpaMinReplicas

hpaMinReplicas returns spec.minReplicas as int64, defaulting to 1 when not set (matching the Kubernetes default).

{{ hpaMinReplicas .hpa }}  → 2

hpaScaleTargetKind

hpaScaleTargetKind returns the kind of the workload the HPA scales (spec.scaleTargetRef.kind).

{{ hpaScaleTargetKind .hpa }}  → "Deployment"

hpaScaleTargetName

hpaScaleTargetName returns the name of the workload the HPA scales (spec.scaleTargetRef.name).

{{ hpaScaleTargetName .hpa }}  → "web"

hpaScaling

hpaScaling returns true when the HPA has a valid metric (ScalingActive=True) and currentReplicas != desiredReplicas — a real scale-out or scale-in is in progress. Returns false when the metric source is unknown, which would otherwise cause a misleading true due to desiredReplicas=0.

{{ hpaScaling .hpa }}  → true

hpaScalingActive

hpaScalingActive returns true when the ScalingActive condition is True — the HPA can read its metric and is permitted to scale. False when the metric source is unknown (../<unknown>/80%) or the HPA is otherwise disabled.

{{ hpaScalingActive .hpa }}  → true

hpaScalingLimited

hpaScalingLimited returns true when the ScalingLimited condition is True — the desired replica count was clamped by the min or max bound.

{{ hpaScalingLimited .hpa }}  → false