Home/Labs/HPA + Node Autoscaler Math
All 280 Labs
INTERACTIVE LAB📈

Two-Tier Autoscaling Lab (Interactive)

Run the real HPA formula each reconcile tick, then force pending pods to trigger Karpenter or Cluster Autoscaler. Scale pods with ceil(current x currentMetric/target) and follow through to node provisioning latency and right-sizing differences.

Two-Tier Autoscaling: HPA Pod Math + Node Provisioning

Run the real HPA formula — ceil(current × currentMetric / target) — then watch pending pods force a node-tier decision.

Avg pod CPU

66.7%

HPA desired replicas

14

Pending pods (no capacity)

0

Node provisioning ETA

—

Idle — press “Run HPA reconcile tick”

Tier 1 (seconds): the HPA controller polls Metrics Server every 15s; at 66.7% vs a 60% target it computes ceil(12 × 66.7/60) = 14 replicas. Scale-down is throttled by the 5-minute stabilization window to stop thrashing.

Tier 2 (tens of seconds): every pod fits on current nodes — no hardware launch needed, so the pod tier alone absorbs this load.

Self-healing floor: even at steady state, the reconciliation loop keeps actual = declared: a dead pod is replaced before HPA ever notices.

How It Works Under the Hood

Elasticity is two tiers. Tier one, the Horizontal Pod Autoscaler, polls the Metrics Server every fifteen seconds and sets desired replicas to ceil(current x currentMetric/targetMetric); a five-minute stabilization window stops oscillation. Scaling pods only works if nodes have free CPU and RAM, so tier two provisions hardware when pods go Pending. The classic Cluster Autoscaler increments a homogeneous Auto Scaling Group over two to four minutes, while Karpenter bypasses ASGs, groups pending pod requests and launches right-sized heterogeneous instances in 30-45 seconds. Self-healing underpins both: the reconciliation loop always restores declared state.

Core Architectural Principles

  • HPA desired replicas = ceil(Current x CurrentMetric / TargetMetric), recomputed on a 15-second loop.
  • A scale-down stabilization window (default 5 min) prevents thrashing as metrics fall.
  • Karpenter right-sizes heterogeneous nodes in ~45s versus 2-4 min for ASG-based Cluster Autoscaler.
Interview Round Script

State the HPA formula out loud and plug in numbers: ten pods at 85 percent against a 60 percent target yields ceil(10 x 85/60) equals fifteen. Then explain tier two: when those pods exceed node capacity they stay Pending, so the node autoscaler must act, and Karpenter is faster and cheaper than a homogeneous Cluster Autoscaler because it right-sizes via direct cloud fleet APIs. Warn that a liveness probe checking a database causes cluster-wide restart storms.

Key Trade-Offs

Two-tier autoscaling absorbs spikes without paying for idle, but pod scaling is seconds while hardware provisioning lags 30-120 seconds behind.

Related Curriculum Chapter

Kubernetes Deployments, Autoscaling, & Self-Healing

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs