THINK FIRST·CODE LATER

← All labs

Kubernetes Horizontal Pod Autoscaler

Problem

Input: replicas min max target podCapacity, then the load (requests/s) at each step.

At each step: utilization = load / (replicas × podCapacity). If utilization > 1, the step is overloaded. Compute ratio = utilization / target; if |ratio − 1| > 0.1, desired = ⌈replicas × ratio⌉, otherwise desired = replicas; clamp to [min, max]. The desired count becomes the replica count of the next step.

Print step 3: load 300, replicas 3, utilization 100% -> desired 5 (utilization rounded to an integer percent, with OVERLOADED before -> when > 100 %), and at the end Overloaded steps: k, pod-steps used: s (sum of replicas over all steps).

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.