The Horizontal Pod Autoscaler (HPA) is a Kubernetes resource that automatically scales the number of pod replicas in a deployment, replica set, or stateful set based on observed metrics like CPU utilization, memory consumption, or custom application metrics. It operates by periodically querying the Kubernetes Metrics API to compare current metric values against user-defined targets, then instructs the relevant controller to adjust the replica count to maintain the desired performance level. This enables applications to handle variable load efficiently without manual intervention.
Glossary
Horizontal Pod Autoscaler (HPA)

What is Horizontal Pod Autoscaler (HPA)?
A core Kubernetes controller for dynamic resource scaling.
HPA is essential for cost optimization and performance reliability in production environments, particularly for variable-workload services like LLM inference endpoints. It integrates with custom metrics via the Custom Metrics API, allowing scaling based on domain-specific signals such as requests-per-second or queue length. For stateful applications, it should be paired with a PersistentVolume that supports dynamic provisioning. Effective HPA configuration requires defining appropriate resource requests, limits, and stabilization windows to prevent rapid, thrashing scale cycles.
Key Features of HPA
The Horizontal Pod Autoscaler (HPA) is a core Kubernetes controller that automatically adjusts the number of pod replicas in a workload to match observed demand. It is a fundamental component for cost-efficient and resilient application deployment.
Declarative Configuration
HPA is defined and managed as a standard Kubernetes resource using a YAML manifest. This declarative approach integrates seamlessly with GitOps workflows and Infrastructure as Code (IaC) practices.
Key configuration fields include:
scaleTargetRef: References the Deployment, StatefulSet, or other scalable resource to control.metrics: Defines the list of metrics (CPU, memory, custom, external) and their target values.minReplicas/maxReplicas: Sets the hard bounds for the scaling range, preventing runaway scaling.
Changes to the HPA spec are reconciled automatically by the controller, ensuring the observed state matches the declared intent.
Stabilization & Throttling Controls
To prevent rapid, flapping scale events due to metric noise, HPA includes algorithms for stabilization.
- Stabilization Window: A configurable period where the autoscaler looks at historical metric recommendations before acting. A scale-down stabilization window prevents removing pods too quickly after a brief load spike.
- Policies: Define how pods are added or removed. For example, a policy can specify the maximum number of pods that can be added or removed in a single scaling action (
scaleUp/scaleDownpolicies).
These controls are critical for maintaining application stability and avoiding costly, unnecessary churn in cloud environments.
Cooldown/Delay Periods
HPA implements built-in delays after scaling actions to allow metrics to stabilize before evaluating again, preventing a continuous loop of scaling operations.
- Scale-Up Cooldown: After increasing pods, HPA waits a default period (e.g., 3 minutes) before performing another scale-up evaluation. This allows time for new pods to become ready and start serving traffic.
- Scale-Down Cooldown: After decreasing pods, HPA waits a longer default period (e.g., 5 minutes) before another scale-down. This is typically longer than the scale-up delay to be more conservative about removing capacity.
These periods are configurable via the HPA's behavior field, allowing tuning for specific application needs.
Use Case: LLM Inference Serving
In LLM Deployment and Serving, HPA is essential for managing variable inference demand. Since LLM requests are computationally intensive and bursty, static provisioning is inefficient.
- Metric: Scale based on a custom metric like average request latency or GPU utilization percentage from the inference server (e.g., vLLM, TGI).
- Pattern: A surge in user queries increases latency. HPA detects this and adds more pod replicas to share the load. When traffic subsides and latency drops, it scales pods down to save costs.
- Consideration: Due to the large memory footprint of LLMs and cold start latency,
minReplicasis often set >0 to keep a warm pool of models loaded, and scale-down policies are made very conservative.
HPA Metric Types: Resource vs. Custom vs. External
A comparison of the three primary metric source types the Kubernetes Horizontal Pod Autoscaler (HPA) can use to drive scaling decisions, detailing their source, configuration, and typical use cases.
| Feature / Attribute | Resource Metrics | Custom Metrics | External Metrics |
|---|---|---|---|
Primary Data Source | Container resource usage (cAdvisor -> metrics-server) | Application-level metrics from custom metrics API | Metrics from systems outside the Kubernetes cluster |
Kubernetes API Dependency | metrics.k8s.io (core metrics API) | custom.metrics.k8s.io | external.metrics.k8s.io |
Typical Metric Examples | CPU utilizationMemory utilization | HTTP requests per secondQueue lengthApplication error rate | Cloud Pub/Sub queue backlogCustom Datadog metricAWS SQS ApproximateNumberOfMessages |
Metric Target Type | UtilizationPercentage (e.g., targetCPUUtilizationPercentage) | Value (e.g., targetValue, AverageValue) | Value (e.g., targetValue) |
Configuration Complexity | Low (often enabled by default) | Medium (requires metrics adapter deployment) | High (requires external provider integration & adapter) |
Requires Custom Adapter Deployment | |||
Use Case | Scaling based on compute resource pressure (CPU/Memory) | Scaling based on business logic or application performance | Scaling based on external event sources or infrastructure load |
Latency to Metric Availability | < 30 seconds | Varies (depends on adapter scrape interval) | Varies (depends on external system & adapter) |
HPA Use Cases in LLM Serving
The Horizontal Pod Autoscaler (HPA) is a critical Kubernetes component for dynamically scaling LLM inference workloads. In production LLM serving, scaling is driven by complex, custom metrics beyond simple CPU and memory.
Scaling on Inference Latency (P95/P99)
Maintaining a consistent user experience requires scaling based on performance Service Level Objectives (SLOs). HPA can scale out when tail-end latency degrades.
- How it works: A monitoring system (e.g., Prometheus with a dedicated exporter) tracks the 95th or 99th percentile (P95/P99) latency of inference requests. This metric is fed to HPA.
- Target Example: Scale up when the P99 latency exceeds 1500ms, aiming to bring it back below 1000ms.
- Advantage: This is a user-centric metric that directly correlates with quality of service. It accounts for bottlenecks not visible in raw utilization, such as network contention or model loading delays.
Scaling on Queue Length
For batch inference or high-throughput async processing, scaling can be driven by the backlog of pending requests in a work queue.
- How it works: The number of pending tasks in a queue (e.g., Redis, RabbitMQ, Kafka) is exposed as a custom metric. HPA adds worker pods to consume the backlog.
- Use Case: Ideal for offline processing jobs, document summarization pipelines, or embedding generation where immediate latency is less critical than throughput.
- Implementation: Requires a metrics collector that can query the queue's API. The HPA target is set to maintain a near-zero queue depth under normal load.
Multi-Metric & Custom Metric Composition
Production LLM serving often requires sophisticated scaling logic based on a combination of metrics to avoid over- or under-provisioning.
- How it works: HPA can be configured with multiple metric targets. Scaling occurs based on the highest calculated replica count from all metrics.
- Common Composite Strategy:
- Scale up if GPU utilization > 70% AND request queue length > 50.
- Scale down only if GPU utilization < 30% AND request rate < threshold for a sustained period.
- Tooling: This often requires writing custom Prometheus Recording Rules to create a single derived metric that encapsulates the complex logic, which HPA then consumes.
Predictive Scaling with External Metrics
HPA can integrate with external systems to enable predictive scaling based on known traffic patterns or business events.
- How it works: HPA's
Externalmetric type allows it to scale based on data from outside the Kubernetes cluster. This could be a metric from a cloud monitoring service or a custom forecasting service. - Example:
- A cron job predicts high traffic for a product launch at 9 AM and publishes a high target metric value at 8:30 AM, triggering a proactive scale-up.
- Scale based on a business metric like "concurrent active users" from an application database.
- Benefit: Eliminates the cold-start latency penalty by having pods ready before the traffic surge arrives.
Frequently Asked Questions
Essential questions about the Kubernetes Horizontal Pod Autoscaler (HPA), a core resource for automatically scaling LLM inference workloads based on real-time demand.
The Horizontal Pod Autoscaler (HPA) is a Kubernetes controller that automatically adjusts the number of pod replicas in a deployment or replica set based on observed utilization of specified metrics. It works by periodically querying the Kubernetes Metrics API (or a custom metrics API) to check the current metric values against the target values defined in the HPA specification. If the average metric value across all pods exceeds the target, the HPA instructs the deployment to scale up, creating more replicas to handle the load. Conversely, if utilization is below the target, it scales down to reduce resource consumption. This creates a feedback loop that maintains application performance within defined parameters.
Key Components:
- Target Metric: The resource (e.g., CPU, memory) or custom metric to monitor.
- Target Value: The desired average utilization per pod (e.g., 70% CPU).
- Min/Max Replicas: The bounds within which the HPA can operate.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
The Horizontal Pod Autoscaler (HPA) is a core component of Kubernetes' scaling architecture. Understanding these related concepts is essential for designing resilient, self-healing applications.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us