Load is rarely even: at night it is several times lower than in the daytime, while promotions and surges produce spikes that are hard to predict in advance. Keeping a standing fleet sized for the peak means paying for idle capacity, and a shortage of resources turns into errors. Autoscaling watches the metrics and changes the number of replicas or nodes so that capacity follows real demand.
How it works
A cycle of four steps is at work: a controller periodically measures a metric, compares it with the target value, decides how many objects are needed, and adds or removes them. The limits are set in advance: a minimum so that the service does not disappear, and a maximum so that the budget is not exceeded.
| Step | What happens |
|---|---|
| Measurement | every few seconds the controller reads metrics: CPU utilisation, memory, queue length, requests per second per replica |
| Comparison | the current value is compared with the target — for example, 60% CPU utilisation per replica; a deviation within the tolerance (10% by default) is ignored |
| Calculation | using the formula for the desired number of replicas: multiply the current number by the ratio of the measured value to the target and round up |
| Execution | surplus replicas are removed and missing ones added; a new replica counts only once it is ready to serve traffic |
Example: a service keeps CPU utilisation of each replica at about 60%; there are four replicas, and utilisation has risen to 90%. The controller computes 4 × 90 / 60 = 6 and adds two replicas. When traffic subsides and utilisation drops below the target, the surplus replicas will be removed.
Where it is used: Kubernetes and the cloud
In Kubernetes, autoscaling is split into three mechanisms: one changes the number of pods, another the resources of pods, and the third the number of cluster nodes. In the cloud, autoscaling groups play the same role for virtual machines.
| Mechanism | What it scales | What it decides on |
|---|---|---|
| HPA (Horizontal Pod Autoscaler) | the number of pods | CPU and memory utilisation relative to requests, custom metrics — requests per second, queue length |
| VPA (Vertical Pod Autoscaler) | resource requests and limits of pods | actual CPU and memory consumption |
| Cluster Autoscaler | the number of cluster nodes | pods that did not fit on the existing nodes, and nodes left idle for long stretches |
| Groups in the cloud (Auto Scaling group in AWS, Virtual Machine Scale Sets in Azure, MIG in Google Cloud) | the number of virtual machines | CPU utilisation, load balancer metrics, schedules, machine health |
The mechanisms work together: HPA adds pods when there is no room for them, Cluster Autoscaler adds nodes to run them on, and when load falls it removes the idle ones. Alongside it, Karpenter is being developed — another open source node autoscaler.
What to configure in advance
- A minimum and a maximum: without them the controller will either burn through the budget or fail to survive a spike.
- Resource requests on the pods: without them HPA cannot work out utilisation and cannot make a decision.
- A stabilisation window — a pause between changes so that a brief spike does not make the size jitter; in HPA it defaults to 5 minutes for scaling down.
- A metric that genuinely correlates with load and updates in time: with a lagging indicator the controller scales only after the spike has passed.
- Correct readiness probes: a replica may be removed only when it is not serving requests.
Sources
the term is written from these pages- Kubernetes — Horizontal Pod Autoscalerkubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/(opens in a new tab)
- Kubernetes — репозиторий kubernetes/autoscaler (VPA, Cluster Autoscaler)github.com/kubernetes/autoscaler(opens in a new tab)
- AWS — What is Amazon EC2 Auto Scaling?docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html(opens in a new tab)
Verified 18 Nov