Horizontal Pod Autoscaling in Kubernetes: Growing and Shrinking with Demand

Horizontal Pod Autoscaling in Kubernetes: Growing and Shrinking with Demand

A beginner-friendly guide to how Kubernetes automatically adds and removes copies of your application as traffic rises and falls, how it decides how many are enough, and how to keep it calm, safe, and predictable.

Picture a busy tea stall near a railway station. In the quiet afternoon, one person behind the counter is plenty. When a train arrives and a hundred passengers rush over, that one person is overwhelmed and the queue stretches around the corner. A clever owner would call in extra helpers when the crowd builds up and send them home when the platform empties. Nobody wants to pay ten helpers all day, and nobody wants customers waiting forever. Horizontal Pod Autoscaling is that clever owner for your application: it watches the crowd and adjusts the number of helpers automatically.

1What Does “Scaling” Mean?

Before we automate anything, let us understand the two basic ways an application can grow.

Two Directions of Growth

When an application gets busier than it can handle, there are two classic answers. The first is to make the machine bigger: give it more processor power and more memory. This is called vertical scaling, like replacing a small cooking pot with a giant one. The second is to run more copies of the application side by side and share the work between them. This is called horizontal scaling, like opening more cooking pots on more burners.

Simple Analogy

A supermarket with a long queue can install one bigger, faster billing counter, or it can open five more ordinary counters. The first is vertical scaling, the second is horizontal. Kubernetes is especially good at the second approach, because opening one more identical counter is quick and cheap.

Why Horizontal Suits Kubernetes

Kubernetes runs your application in small identical units called Pods. Adding another Pod is simply asking Kubernetes to start one more copy. There is a natural limit to how large a single machine can get, but there is almost no limit to how many copies you can run. That is why horizontal scaling is the default way of handling growth in the Kubernetes world.

i
Good to Know

Horizontal scaling works best for applications that can run as many identical copies, where any copy can serve any request. Applications that keep important private state inside one copy need extra care.

2Why Manual Scaling Fails

If humans must adjust the number of copies, the system is always one step behind.

The Problem with Fixed Numbers

Without automation, a team picks a number of Pods and hopes it is right. If they choose too few, users suffer slow pages and errors during busy hours. If they choose too many, the company pays for machines that sit idle most of the day. Traffic is rarely steady. It rises with morning routines, sales, news events, and month-end deadlines, and it falls at night.

Simple Analogy

Imagine a wedding caterer who must decide the number of cooks one week before the wedding and can never change it. Too few cooks and guests go hungry. Too many and money is wasted. A smart caterer calls in extra cooks as the hall fills up.

Too few
Slow responses and errors at peak
Too many
Wasted money during quiet hours
Just right
Only possible if it keeps adjusting

People Are Too Slow

Even a very attentive engineer cannot watch charts around the clock. Traffic spikes can arrive in minutes, at three in the morning, on a holiday. A software loop that checks every few seconds and acts immediately is far faster and never gets tired.

3Core Building Blocks You Must Know

Eight small terms carry almost the entire story of autoscaling.

Term 1

Pod

The smallest running unit in Kubernetes, holding one or more containers. Scaling means changing how many Pods run.

Term 2

Deployment

An object that keeps a chosen number of identical Pods running and replaces them during updates.

Term 3

Replicas

The number of identical Pod copies that should be running. This is the number the autoscaler changes.

Term 4

HorizontalPodAutoscaler

The Kubernetes object that says what to scale, between which limits, and based on which measurements.

Term 5

Metric

A measurement of how busy something is, such as processor use, memory use, or requests per second.

Term 6

Metrics Server

A small cluster add-on that collects live processor and memory readings from every Pod.

Term 7

Target Value

The level of busyness you consider healthy, for example “keep average processor use around sixty percent”.

Term 8

Resource Requests

The amount of processor and memory a container asks Kubernetes to reserve. Percentages are measured against this.

Simple Analogy

The Deployment is the tea stall, the Pods are the helpers, the metric is how long the queue is, the target is “no queue longer than five people”, and the HorizontalPodAutoscaler is the owner who calls helpers in or sends them home to meet that target.

4How the Autoscaler Works at a Glance

The whole idea is a simple loop: measure, compare, adjust, repeat.

A Loop Inside the Control Plane

The Horizontal Pod Autoscaler, often shortened to HPA, is not a separate program you install. It is a control loop built into the cluster’s brain, the control plane. Every so often, by default about every fifteen seconds, the loop wakes up and checks each HPA object in the cluster. For each one, it reads the current measurements, compares them with the target, decides how many Pods are needed, and updates the replica count on the workload if the number should change.

flowchart LR
    A["Users send traffic"] --> B["Pods do the work"]
    B --> C["Metrics Server collects readings"]
    C --> D["HPA control loop"]
    D -->|"Compare with target"| E{"Change needed?"}
    E -->|"Yes"| F["Update replica count on Deployment"]
    E -->|"No"| D
    F --> G["Deployment adds or removes Pods"]
    G --> B
        
FIG 1 — The autoscaling loop of measure, compare, adjust, and repeat

Notice that the autoscaler never starts or stops Pods itself. It only changes the desired number on the workload. The Deployment then does the actual work of creating or removing Pods, exactly as it would if a human had changed the number by hand.

i
Key Idea

The HPA is a thermostat, not a machine. A thermostat does not make heat. It only watches the temperature and tells the heater to work harder or rest. The HPA watches load and tells the Deployment to run more or fewer Pods.

5Where the Numbers Come From: Metrics

An autoscaler is only as good as the measurements it can see.

The Metrics Server

For basic processor and memory readings, Kubernetes relies on the Metrics Server, a lightweight add-on. It asks every node for fresh readings from its Pods and exposes them through the cluster’s standard interface. If the Metrics Server is missing or broken, an HPA that depends on processor or memory has nothing to read and cannot make decisions.

Three Families of Metrics

Resource Metrics

Processor and memory use, measured for each Pod. These are the easiest to start with and are supplied by the Metrics Server. You can even measure a single container inside a multi-container Pod.

Custom Metrics

Measurements that come from inside your own application or from Kubernetes objects, such as requests handled per second, active connections, or items waiting in an internal queue. They need an extra adapter that connects a monitoring system to the cluster.

External Metrics

Measurements that come from outside the cluster entirely, such as the length of a message queue in a cloud service, or the number of jobs waiting in a scheduling system. They also need an adapter.

Simple Analogy

Resource metrics are like checking how tired the helpers look. Custom metrics are like counting the customers in the queue. External metrics are like looking at how many trains are about to arrive, information that comes from outside the stall itself.

!
Common Mistake

Assuming processor use always reflects real demand. An application waiting on a slow database may be badly overloaded from the user’s view while its processor sits nearly idle. Pick a metric that truly tracks the work.

6The Scaling Formula in Plain Words

The math behind the HPA is short enough to do in your head.

The Idea

The autoscaler takes the current number of Pods and multiplies it by a ratio: the current measurement divided by the target measurement. Then it rounds the result up to the next whole number. That result is the number of Pods it wants.

For example, suppose four Pods are running and you want average processor use to stay near fifty percent, but the real average is now one hundred percent. The ratio is two. Four times two is eight, so the autoscaler asks for eight Pods. If, instead, the real average were only twenty-five percent, the ratio would be one half. Four times one half is two, so it asks for two Pods.

Current PodsCurrent AverageTargetRatioPods Wanted
4100 percent50 percent2.08
425 percent50 percent0.52
655 percent50 percent1.17
652 percent50 percent1.046, since the change is too small to act on
Simple Analogy

If four helpers are each twice as busy as they should be, you need twice as many helpers. If they are half as busy, half as many will do. The formula is just that common sense written as arithmetic.

The Tolerance Band

To avoid changing the number for tiny wiggles, the autoscaler ignores small differences. By default, if the ratio is within about ten percent of one, it leaves things alone. This quiet zone stops constant, pointless nudging.

“Scale by the ratio of how busy you are to how busy you want to be.”

7Limits and Targets: Setting the Rules

An HPA object is mostly a short list of decisions you make once.

1

Choose What to Scale

Point the HPA at a workload such as a Deployment or a StatefulSet. It works with anything that can report and change its replica count. It does not apply to workloads that run exactly one Pod per node.

2

Set the Minimum

The smallest number of Pods allowed, even when the system is quiet. This protects availability. One Pod is risky, because if it fails there is nobody left to serve traffic.

3

Set the Maximum

The largest number of Pods allowed, no matter how busy things get. This is your safety belt against runaway cost and against overwhelming other parts of the system.

4

Pick the Metrics and Targets

Decide which measurements matter and what healthy looks like for each of them.

Three Ways to Express a Target

Type 1

Utilization

A percentage of what each Pod requested, for example sixty percent of its reserved processor. Used with resource metrics.

Type 2

Average Value

The average measurement per Pod, for example one hundred requests per second per Pod.

Type 3

Total Value

A single overall number for the whole set, for example a queue that should stay below a chosen length.

!
Common Mistake

Setting the minimum and maximum equal, or setting the maximum far too low. In both cases the autoscaler has no room to move, and you have paid for the complexity without getting any benefit.

8Why Resource Requests Matter So Much

A percentage is meaningless unless you know what it is a percentage of.

Percent of What?

When you set a target such as “sixty percent processor use”, Kubernetes measures each Pod’s real use against what the Pod requested. If a Pod requested one unit of processor and is using six tenths of a unit, it is at sixty percent. If no request was set, there is nothing to compare against, and the autoscaler cannot compute a percentage at all. It will report that it is unable to calculate.

Simple Analogy

Saying “the water tank is sixty percent full” only means something if you know the size of the tank. The request is the size of the tank. Without it, the percentage has no meaning.

Requests Shape Behaviour

If the request is set too low, Pods will look very busy against it, and the autoscaler will add too many copies. If the request is set too high, Pods will look idle, and the autoscaler will hold back when it should be adding more. Getting requests roughly right is the most important preparation for a successful autoscaler.

When Requests Are Realistic

  • Utilization percentages reflect true load
  • Scaling decisions feel proportional and sensible
  • The scheduler places Pods on suitable machines
  • Costs track actual demand

When Requests Are Wrong

  • Too-low requests cause over-scaling and wasted money
  • Too-high requests cause under-scaling and slow responses
  • Missing requests stop the autoscaler from working
  • Behaviour looks random and is hard to explain

9Scaling on Custom and External Signals

Processor use is a proxy. Sometimes you can measure the real thing.

Measuring What Users Feel

Users do not care how hot your processors are. They care how quickly their pages load. A metric that is closer to user experience often leads to better decisions. Requests per second per Pod, the number of active sessions, or the delay before a request gets an answer can all be used as scaling signals.

Queues as a Signal

Applications that process background work, such as sending emails or resizing images, usually pull jobs from a queue. The most natural scaling signal for them is the queue itself: if many jobs are waiting, add workers, and if the queue is empty, remove them. That signal lives outside the cluster in a queue service, so it is an external metric.

Simple Analogy

A post office does not decide how many clerks to hire by feeling how tired they are. It looks at how many letters are waiting in the sorting tray. The length of the tray is a far more direct signal of the work to be done.

The Adapter Layer

To use these richer signals, teams install an adapter that translates readings from a monitoring system into the format the autoscaler understands. Some teams also use an event-driven autoscaling add-on that supports many kinds of triggers and can even scale a workload down to zero copies when nothing is happening, which the standard HPA does not do by default.

i
Practical Tip

Start with processor as a simple baseline. Move to a request-rate or queue-based signal only once you have evidence that processor does not track your real demand.

10Using More Than One Metric

Sometimes one signal is not enough to describe how busy an application is.

Every Metric Gets a Vote

An HPA can watch several metrics at once, for instance processor and requests per second. For each metric it works out how many Pods it would want on its own. Then it picks the largest of those answers. This way, whichever signal is under the greatest pressure wins, and no signal is ignored.

flowchart TD
    A["Processor metric says 6 Pods"] --> D["HPA picks the largest"]
    B["Requests per second metric says 9 Pods"] --> D
    C["Queue length metric says 4 Pods"] --> D
    D --> E["Final decision is 9 Pods"]
        
FIG 2 — With several metrics, the highest recommendation wins
Simple Analogy

Three managers each say how many extra helpers the stall needs. One says six, one says nine, one says four. The owner plays safe and calls in nine, because otherwise the manager who asked for nine would be left struggling.

!
Common Mistake

Adding many metrics without understanding them. More signals mean more ways for a strange reading to push the count up. Every metric you add should have a clear reason to exist.

11Timing: How Fast Does It React?

Autoscaling is quick, but it is not instant, and knowing the delays helps you plan.

The Chain of Small Delays

From the moment traffic surges to the moment new Pods serve users, several small delays add up. First, the metrics need time to be collected and refreshed. Second, the autoscaler only checks on its regular rhythm, by default every fifteen seconds. Third, the new Pods must be scheduled onto a machine, which may take extra time if no machine has room. Fourth, the container image may need to be downloaded. Fifth, the application must start and become ready to accept traffic.

1

Metrics Refresh

Readings are gathered every few seconds, so the autoscaler is always looking at slightly old news.

2

Autoscaler Checks In

The control loop runs about every fifteen seconds and may need one or two rounds to react fully.

3

Pods Get Scheduled

New Pods need somewhere to run. If the machines are full, they wait until more capacity appears.

4

Images and Startup

The image may need downloading, and the application may take time to warm up before it is truly ready.

5

Traffic Starts Flowing

Only once a Pod passes its readiness check does it receive user traffic and share the load.

i
Practical Tip

Because the whole chain can take a minute or more, set your targets a bit below full capacity. A target near sixty or seventy percent leaves spare room while new Pods are still starting.

12Scaling Behavior: Calm Growth and Careful Shrinking

Without brakes, an autoscaler can swing wildly. Behavior settings are the brakes.

The Flapping Problem

Imagine traffic that bounces up and down every minute. A naive autoscaler would add Pods, then remove them, then add them again, constantly. This is called flapping. Each swing wastes resources, may drop connections, and can make the application unstable. The cure is to be quick to grow and slow to shrink.

Simple Analogy

If you send helpers home the moment the queue looks short, you might have to call them all back five minutes later when the next crowd arrives. It is wiser to wait a while before deciding the rush is truly over.

Two Tools

Tool 1

Stabilization Window

A period during which the autoscaler remembers its recent recommendations and picks a safe one. By default, scaling down waits about five minutes, while scaling up reacts immediately.

Tool 2

Scaling Policies

Speed limits on how many Pods, or what percentage, may be added or removed within a stated period of time.

SettingScale Up DefaultScale Down DefaultPurpose
Stabilization windowNone, react immediatelyAbout five minutesAvoid removing Pods during short dips
Speed limitDouble the Pods or add four, whichever is larger, every fifteen secondsUp to all extra Pods every fifteen seconds, after the windowControl how fast counts change
Policy selectionChoose the most permissive policyChoose the most permissive policyDecide which limit applies when several exist
!
Common Mistake

Shrinking the scale-down window to make savings appear faster. It often saves a little money and costs a lot of stability, because Pods disappear just before the next wave of traffic.

13Readiness, Startup, and New Pods

A Pod that is starting up can fool the autoscaler if you are not careful.

New Pods Look Strange

When a Pod first starts, its processor use is often unusually high while it loads code and warms caches, and its readings are unreliable for a short time. If the autoscaler took those early readings at face value, it might think the load is enormous and add far too many Pods. To prevent this, the autoscaler treats Pods that are not yet ready, or that are very new, more cautiously. It gives them a short initialization period during which their processor readings are set aside or handled conservatively.

Readiness Checks Are Essential

A readiness check tells Kubernetes when a Pod is genuinely prepared to receive traffic. Without a proper one, Kubernetes may send users to a Pod that is still starting, which causes errors, and the autoscaler may mistake half-started Pods for healthy capacity. A good readiness check is the single best partner for autoscaling.

Simple Analogy

A new helper who has just arrived is still tying their apron and finding the sugar. Counting them as fully working from the first second would give a false picture. It is better to count them only when they are truly ready to serve.

Graceful Endings Matter Too

When the autoscaler shrinks the group, Pods are told to stop. A well-built application finishes the requests it is handling and closes connections politely before exiting. Combined with a disruption budget, which limits how many Pods can be removed at once, this keeps scale-down from hurting real users.

14HPA and Its Cousins

Kubernetes has several autoscalers, and each solves a different problem.

AutoscalerWhat It ChangesQuestion It AnswersTypical Trigger
Horizontal Pod AutoscalerNumber of PodsHow many copies do we need?Processor, memory, custom, or external metrics
Vertical Pod AutoscalerSize of each Pod’s requestsHow big should each copy be?Observed resource use over time
Cluster AutoscalerNumber of machinesDo we have enough room for all Pods?Pods that cannot be scheduled
Event-driven autoscalersNumber of Pods, including zeroIs there work waiting from an event source?Queue depth, events, schedules
Simple Analogy

The HPA decides how many helpers stand at the tea stall. The vertical autoscaler decides how big an apron and how many tools each helper gets. The cluster autoscaler decides whether the railway station needs more shop space to fit all those helpers.

How They Work Together

The HPA and the cluster autoscaler form a natural team. When the HPA asks for more Pods and the machines are full, the new Pods sit waiting. The cluster autoscaler notices those waiting Pods and adds machines. Once the traffic falls, the HPA removes Pods, and the cluster autoscaler later removes machines that are no longer needed.

!
Common Mistake

Letting the horizontal and vertical autoscalers both react to the same processor or memory measurement on the same workload. They can pull in opposite directions and fight each other. Use them on different signals, or let the vertical one only give recommendations.

15Life of a Traffic Spike

Let us follow one busy moment from the first surge to the return of calm.

sequenceDiagram
    participant U as Users
    participant P as Pods
    participant M as Metrics Server
    participant H as HPA Loop
    participant D as Deployment
    participant C as Cluster Autoscaler
    U->>P: Traffic surges
    P->>M: Report high processor use
    H->>M: Read current metrics
    M-->>H: Average is far above target
    H->>D: Raise replica count
    D->>P: Create new Pods
    P-->>C: Some Pods cannot be scheduled
    C->>C: Add a machine
    P-->>U: New Pods become ready and share load
    Note over H,D: After traffic falls the HPA waits out the stabilization window
    H->>D: Lower replica count gradually
        
FIG 3 — From surge to recovery, step by step
1

Load Rises

Existing Pods become busier, and their processor readings climb above the target.

2

The Loop Notices

At its next check, the autoscaler reads the readings and applies the ratio formula to find the new number.

3

Replicas Increase

The desired count on the Deployment goes up, within the limits and speed rules you configured.

4

Capacity Is Found

New Pods are scheduled. If needed, extra machines are added so that they have room to run.

5

Load Is Shared

Once ready, the new Pods take a share of traffic and the average busyness drops back toward the target.

6

The Rush Ends

When traffic falls, the autoscaler waits out its stabilization window, then removes Pods gradually.

16When Things Go Wrong: Failure Modes and Fixes

Most autoscaling problems fall into a few familiar shapes.

The Autoscaler Shows “Unknown” Instead of a Number

It cannot read the metric. Common causes are a missing or unhealthy Metrics Server, missing resource requests on the containers, or a broken custom-metrics adapter.

It Never Scales Up

Possible causes include the maximum already being reached, the target set too high, the metric not reflecting real load, or the tolerance band swallowing small differences.

New Pods Stay Pending

The autoscaler did its job, but there is no room on any machine. Fix by adding capacity, enabling the cluster autoscaler, or checking that requests are not larger than any machine can hold.

It Scales Up and Down Repeatedly

Flapping. Widen the scale-down stabilization window, add gentler speed limits, or choose a smoother metric.

The Replica Count Resets After a Deployment Update

The workload description still contains a fixed replica number, and every re-apply pushes it back. When using an HPA, leave the replica field out of the description so the autoscaler owns that number.

A Calm Debugging Path

1

Read the HPA Status

Look at the current and target values, the desired replicas, and the conditions. They say whether scaling is active, limited, or unable to work.

2

Check the Events

Events explain each scaling decision and each failure to fetch a metric, often naming the exact cause.

3

Verify the Metrics Source

Make sure the Metrics Server or adapter is running and returning current numbers for your Pods.

4

Inspect Requests and Limits

Confirm every container in the Pods has a sensible request, since percentages depend on it.

5

Watch for Pending Pods

If new Pods are not running, investigate scheduling and capacity before blaming the autoscaler.

17Security and Safety Considerations

Automatic growth is powerful, and power needs guardrails.

Risk 1

Runaway Cost

A traffic flood, a bug, or an attack can push the autoscaler to the maximum and run up a large bill.

Risk 2

Denial of Wallet

Attackers may send junk traffic on purpose, not to crash the site but to force expensive scaling.

Risk 3

Overloading Dependencies

More Pods mean more connections to databases and other services, which may collapse under the new pressure.

Risk 4

Tampering with Autoscaler Rules

Anyone allowed to edit an HPA can change limits or targets, affecting cost and availability.

Risk 5

Untrusted Metric Sources

A compromised metrics adapter can report false numbers, tricking the autoscaler into growing or shrinking wrongly.

Simple Analogy

An owner who hires helpers automatically needs a budget cap. Otherwise a prankster who keeps ringing the doorbell in a crowd-like pattern could make the stall hire a hundred helpers overnight.

Practical Protections

Set a sensible maximum replica count as a hard cost ceiling, and use namespace resource quotas as a second wall. Put rate limits and protection against abusive traffic in front of the application. Size database connection limits so the maximum number of Pods cannot exhaust them. Use role-based permissions so only trusted people can create or change autoscalers and the metrics adapters they depend on. Alert on unexpected growth so a human is told when the count stays near the maximum.

!
Common Mistake

Treating the maximum as a value you set once and forget. It is a business decision about the most you are willing to spend and the most your dependencies can bear, so review it whenever the system around it changes.

18Monitoring, Logging, and Metrics for the Autoscaler Itself

The autoscaler makes decisions for you, so you should be able to see and question them.

The Signals Worth Watching

Watch the current number of replicas against the desired number, the metric values compared with their targets, and how long the autoscaler sits at its minimum or maximum. Also watch how often the replica count changes. A count that changes every few minutes suggests flapping. A count pinned at the maximum for hours suggests the limit is too low or something is wrong.

Replicas
Current versus desired count over time
Metrics
Measured value versus the target
Limits
Time spent stuck at minimum or maximum
What to WatchWhy It MattersWarning Sign
Desired versus current replicasShows whether scaling is keeping upLarge gap that lasts a long time
Metric versus targetShows if the autoscaler sees real pressureMetric far above target with no growth
Scaling conditionsReport whether scaling is active or limitedRepeated unable-to-scale messages
Pending PodsShows whether capacity is the bottleneckPods waiting for long periods
Response time and errorsThe user-facing truthRising latency even after scaling

Learning from History

Record each scaling event alongside traffic and response-time charts. Reviewing them after a busy day tells you whether the autoscaler reacted early enough, whether targets were too tight or too loose, and whether the limits were right. Treat autoscaling settings as living settings that improve with evidence.

19Design Patterns and Anti-Patterns

Good habits make autoscaling quiet and dependable.

Pattern: Stateless Front Ends

Design services so any copy can serve any request, keeping user state in a shared store. This makes adding and removing Pods safe and easy.

Pattern: Generous Minimum, Firm Maximum

Keep at least two or three Pods for resilience, and set a maximum tied to budget and dependency limits.

Pattern: Fast Up, Slow Down

Allow quick growth for sudden spikes, and use a longer stabilization window to shrink gently.

Pattern: Queue-Driven Workers

Scale background workers by queue length rather than processor, so capacity follows the amount of waiting work.

Pattern: Scheduled Warm-Up for Known Events

When a big event is predictable, such as a sale at noon, raise the minimum shortly before it starts, so the system is ready before the rush arrives.

ANTI-PATTERN-01 Avoid
Problem

Enabling autoscaling on containers that have no resource requests.

Why It’s Harmful

Percentage targets cannot be computed, so the autoscaler reports unknown and never scales. The team believes they are protected when they are not.

Correct Approach

Set realistic requests based on measured usage before creating the autoscaler, and review them regularly.

ANTI-PATTERN-02 Avoid
Problem

Setting a very high maximum, or none that matches reality, and ignoring downstream limits.

Why It’s Harmful

A surge can scale the front end so far that the database or a partner service is overwhelmed, turning a busy day into an outage and a large bill.

Correct Approach

Derive the maximum from what dependencies can handle and what the budget allows, and protect dependencies with their own limits.

ANTI-PATTERN-03 Avoid
Problem

Relying on autoscaling to fix slow code or a database bottleneck.

Why It’s Harmful

Adding Pods does not speed up a shared slow dependency. It only adds more callers waiting in line, which can make things worse.

Correct Approach

Find and fix the real bottleneck first, then use autoscaling to handle honest growth in demand.

20Best Practices and Common Mistakes

A short checklist that prevents most autoscaling trouble before it starts.

Best Practices

  • Set realistic resource requests before enabling autoscaling
  • Use proper readiness checks and graceful shutdown
  • Keep a minimum of at least two Pods for important services
  • Pick targets with headroom, around sixty to seventy percent
  • Choose metrics that reflect real demand, not just processor
  • Load test to see how the system really behaves under growth
  • Use a disruption budget to protect availability during scale-down

Common Mistakes

  • Leaving a fixed replica number in the workload description
  • Ignoring startup time when choosing targets
  • Combining horizontal and vertical scaling on the same signal
  • Forgetting to set or review the maximum
  • Never testing scale-down behaviour
  • Assuming autoscaling can fix an application bottleneck
i
Habit to Build

Before every big event, ask three questions. Can the metrics be read? Is there room for more Pods? Can everything behind the application cope with the maximum? If all three answers are yes, autoscaling will carry you through.

21Real-World Examples

Here is how autoscaling quietly powers everyday systems.

Online Shop on Sale Day

A shopping site runs four Pods on a normal morning. When a flash sale begins, traffic multiplies, and the autoscaler grows the front end to dozens of Pods within minutes. After the sale ends, it shrinks slowly back, so shoppers who linger are never dropped.

Ticket Booking Opening at Noon

A booking service knows tickets go on sale at noon. The team raises the minimum count a few minutes earlier so capacity is already waiting, and lets the autoscaler handle any extra demand on top.

Video Processing Workers

A media company converts uploaded videos. Uploads arrive in bursts, so worker Pods scale by the number of jobs waiting in the queue. When the queue is empty, workers shrink to a small baseline and save money.

News Site During Breaking Stories

A news website sees sudden, sharp traffic when a big story breaks. It scales on requests per second per Pod, which reacts faster than processor use, and keeps a generous minimum during the day to absorb the first wave.

Internal Reporting Tool

A company dashboard is busy at the start of the working day and month-end, and idle at night. Autoscaling keeps costs low overnight while remaining responsive when hundreds of employees log in at once.

22Frequently Asked Questions

Q1Is the Horizontal Pod Autoscaler installed by default?

The autoscaling logic is part of the cluster’s control plane, so it is available. However, processor and memory scaling also needs the Metrics Server add-on, which some clusters do not include by default.

Q2How often does the HPA check the metrics?

By default about every fifteen seconds. Cluster administrators can change this rhythm, but very short intervals rarely help because the metrics themselves only refresh every few seconds.

Q3Can the HPA scale a workload down to zero Pods?

Not in the normal, default setup. The standard behaviour keeps at least one Pod. Scaling to zero needs an experimental feature or an event-driven autoscaling add-on.

Q4Which workloads can be autoscaled horizontally?

Anything that supports changing its replica count, such as Deployments and StatefulSets. Workloads that run exactly one Pod per machine cannot be scaled this way.

Q5Why does my HPA say the metric is unknown?

Usually the Metrics Server is not working, the containers have no resource requests, or the custom metrics adapter is not returning data. The HPA events normally name the exact cause.

Q6What is the difference between HPA and VPA?

The horizontal autoscaler changes how many Pods run. The vertical autoscaler changes how much processor and memory each Pod asks for. They solve different problems and should not react to the same signal on the same workload.

Q7Why does the HPA scale down so slowly?

It is designed that way. A stabilization window of about five minutes stops the system from removing Pods during short dips, which prevents flapping and protects users.

Q8Does autoscaling also add machines to the cluster?

No. The HPA only changes the number of Pods. Adding machines is the job of the cluster autoscaler, which reacts when Pods cannot be scheduled for lack of room.

Q9Can I use more than one metric at once?

Yes. The autoscaler works out the Pod count for each metric separately and then chooses the highest. This keeps the most stressed signal in charge.

Q10Will autoscaling fix a slow application?

Only if slowness comes from too little capacity. If the cause is slow code or a shared bottleneck like a database, adding Pods will not help and may even make matters worse.

23Summary and Key Takeaways

Horizontal Pod Autoscaling is Kubernetes’ way of matching the number of running copies of your application to the amount of work waiting to be done. A simple loop measures how busy your Pods are, compares that with a target you chose, and changes the replica count using a plain ratio. Minimum and maximum limits give safety, behavior settings give calm, and good metrics give accuracy. Combined with sensible resource requests, readiness checks, and a cluster that can add machines, the autoscaler lets your application stay quick during rushes and cheap during quiet hours, without anyone watching the charts at three in the morning.

Key Takeaways

  • Scale out, not just up — Kubernetes handles growth best by adding identical Pod copies, and the HPA automates exactly that.
  • A simple loop and ratio — every few seconds it multiplies current Pods by the ratio of measured to target value and rounds up.
  • Requests make percentages meaningful — without realistic resource requests, utilization targets cannot work.
  • Pick metrics that mirror real demand — processor is a good start, but request rates and queue lengths often reflect users better.
  • Fast up, slow down — stabilization windows and scaling policies prevent flapping and protect users during dips.
  • Limits are guardrails — a sensible minimum protects availability, and a firm maximum protects budget and dependencies.
  • It is a team effort — readiness checks, graceful shutdown, the cluster autoscaler, and healthy dependencies all determine whether scaling truly helps.