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

The traffic source generates realistic, fluctuating workloads that simulate real-world usage patterns, such as gradual morning ramps or sudden Black Friday spikes. It emits request messages to the ingress path, representing user or client requests hitting the application. Dragging the incoming traffic rate slider immediately changes the stream of request dots entering the service.

Application Service

The application service acts as the load balancer and routing layer, representing the Kubernetes Service that distributes traffic to running pods. It receives incoming requests and distributes them using a round-robin routing strategy across all active, healthy pods. Request dots fan out evenly across ready pods, while overload conditions cause excess requests to drop.

Metrics Server

Because HPA cannot make scaling decisions without cluster visibility, the metrics server aggregates utilization statistics across running replicas. It samples CPU and memory metrics from running pods and calculates the average utilization across the active replica set. The scraped average CPU utilization percentage updates on each polling tick as traffic fluctuates.

HPA Controller

The HPA controller implements the control loop that evaluates scraped metrics and decides whether to scale up, scale down, or stay stable. It computes the desired replica count using the ratio formula, checks cooldown constraints, and issues scaling commands to the deployment controller. Its panel displays the target replica calculation alongside the active scale-up and scale-down cooldown timers.

Deployment Controller

The deployment controller executes scaling decisions by managing the lifecycle of individual pod replicas. It creates new pods (which start in a pending state) or terminates existing pods to match the desired replica count. Pod cards on the canvas shift through Pending, Ready, Running, and Terminating states as the controller reconciles the replica pool.

Application Pods

The application pods execute the service workload and absorb incoming client requests once their containers pass readiness checks. Each pod consumes CPU and memory proportional to its assigned request load and transitions from Pending to Ready after the startup delay expires. Newly launched pods count down their boot timer before joining the active load-balancing rotation.

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’s 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.