DevOps intermediate LIVE SIMULATOR
πŸ“ˆ

Auto-Scaling (HPA) Simulator

Simulate Kubernetes Horizontal Pod Autoscaler scaling pod replicas based on CPU utilization. Watch pods spin up and down as traffic changes, experiment with scaling thresholds

auto-scalingHPAKubernetesscalingpodsCPUcooldownsimulator
Interactive Simulator

Continue with the guided workspace

Use the paired workspace to connect this guide's mental model with live component state, visible signals, and the outcome each step or scenario is meant to prove.

Mental Model

Auto-scaling is the process of adjusting computing resources dynamically based on actual demand. In Kubernetes, the Horizontal Pod Autoscaler (HPA) monitors resource metrics (typically CPU utilization) and adjusts the replica count of a deployment to keep average resource utilization near a target threshold.

The core mental model is that auto-scaling is a feedback loop: external traffic increases CPU usage, the metrics server collects CPU samples, the HPA controller evaluates those samples against the target threshold, and the deployment controller adjusts the replica count. A startup delay means new replicas are not ready immediately, and cooldowns prevent the system from overreacting to noisy metric spikes.

Components and Why They Exist

Traffic Source

To generate realistic, fluctuating workloads that simulate real-world usage patterns, such as gradual morning ramps or sudden Black Friday spikes. Emits request messages to the ingress path, representing user or client requests hitting the application. In the demo, watch the incoming traffic rate slider and the resulting visual flow of request dots entering the application.

Application Service Parent

It acts as the load balancer and routing layer, representing the Kubernetes Service that distributes traffic to running pods. Receives incoming requests and distributes them using a round-robin routing strategy across all active, healthy pod children. In the demo, watch how request dots are distributed to active pods, and see if any are dropped when the pods are overloaded.

Metrics Server Parent

HPA cannot make scaling decisions without visibility. The metrics server aggregates utilization stats across the cluster. Samples CPU and memory metrics from running pods and calculates the average utilization across the active replica set. In the demo, observe the average CPU utilization percentage and how it changes in response to traffic fluctuations.

HPA Controller Parent

It implements the control logic that evaluates metrics and decides whether to scale up, scale down, or stay stable. Computes the desired replica count using the ratio formula, checks cooldown constraints, and issues scaling commands to the deployment controller. In the demo, watch the desired replica count update, and observe the scale-up and scale-down cooldown timers.

Deployment Controller Parent

It executes the scaling decisions by managing the lifecycle of individual pod replicas. Creates new pods (which start in a pending state) or terminates existing pods to match the desired replica count. In the demo, watch pods change color and state (e.g., Pending, Ready, Running, or Terminating) on the canvas.

Edge Cases and Misconceptions

  • Scaling is not instantaneous: New pods take time to initialize, pull container images, and pass readiness probes. During this startup delay, the existing pods must absorb the load, which can lead to temporary performance degradation or dropped requests.
  • CPU is not the only metric: Scaling purely on CPU means the autoscaler will miss memory exhaustion issues (like memory leaks), queue backups, or downstream database bottlenecks.
  • Aggressive scale-down is dangerous: Restoring capacity is expensive. Scaling down too quickly during a temporary dip in traffic can leave the system vulnerable to the next traffic wave, causing thrashing.
  • Autoscaling has limits: Min and max replica boundaries protect against unbounded cost or resource exhaustion, but a max limit that is set too low will cause request drops under extreme traffic.
  • Failed pods consume capacity: Pods that are crashing or restarting still consume cluster management resources and count toward the deployment\x27s replicas, even though they cannot serve traffic.

Common Questions

How does the Horizontal Pod Autoscaler (HPA) compute the target replica count?

HPA calculates the desired number of replicas using the ratio formula: desiredReplicas = ceil(currentReplicas * (avgCPU / targetCPU)). The result is then clamped between the configured minReplicas and maxReplicas boundaries.

Why are scale-up and scale-down cooldown periods treated differently?

Scale-up cooldown is usually short to allow the system to respond quickly to traffic spikes and prevent service degradation. Scale-down cooldown (stabilization window) is long to prevent 'thrashing'β€”where the system prematurely destroys replicas during a brief traffic dip, only to have to spin them up again immediately when traffic returns.

What role do Kubernetes readiness probes play in auto-scaling?

Readiness probes ensure that traffic is not routed to a newly created pod until it is fully initialized and ready to serve requests. During the startup delay, the pod is in a 'Pending' or 'ContainerCreating' state; routing traffic to it before it is ready would result in dropped requests.

How does a memory leak affect CPU-based auto-scaling?

CPU-based HPA is blind to memory pressure. A memory leak causes pods to exceed their memory limits and get terminated by the kernel (OOMKill). This triggers container restarts, but if the CPU remains low, HPA will not scale up to replace the lost capacity, resulting in service degradation.

What is scaling thrashing and how do stabilization windows prevent it?

Scaling thrashing is the rapid oscillation between scaling up and scaling down. Stabilization windows prevent this by making the autoscaler look back over a window (e.g., 5 minutes) and choose the highest recommended replica count from that window before executing a scale-down action.