Kubernetes · 8 min read

Kubernetes Autoscaling: HPA, VPA and Cluster Autoscaler Explained

Scaling is most effective when each layer reacts to the signal it can actually control.

Abstract VexEagle cloud engineering artwork for Kubernetes Autoscaling: HPA, VPA and Cluster Autoscaler Explained

Fundamentals and why this matters

Kubernetes autoscaling works only when each layer has an appropriate signal and enough time to act. Horizontal Pod Autoscaler changes replica count; Vertical Pod Autoscaler recommends or adjusts pod requests; Cluster Autoscaler or Karpenter adds and removes node capacity. These controllers interact with requests, limits, readiness, scheduling, pod startup time, and application behavior. A deployment can be perfectly configured syntactically and still scale too late for real traffic.

Architecture and important components

HPA reads CPU, memory, or custom/external metrics through Metrics Server or a metrics adapter, then adjusts the desired replicas of a target such as a Deployment. Pods need sensible resource requests so the scheduler and HPA have meaningful data. When new pods cannot schedule, Cluster Autoscaler can add nodes; Karpenter can provision capacity based on workload requirements. Readiness probes prevent traffic before startup is complete. PodDisruptionBudgets preserve minimum availability during voluntary disruption.

Production implementation guidance

Start with a load profile and a clear scale signal. CPU can work for compute-bound services; request rate, concurrency, or queue depth can be better for I/O-bound APIs and workers. Set min replicas for failure headroom, max replicas for downstream protection, and stabilization windows to avoid oscillation. Measure image pull time, initialization, cache warmup, and dependency connection behavior because they determine whether scale-out arrives in time. Consider small over-provisioning or warm capacity for sharp traffic spikes.

A CPU-based HPA starting point

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api
spec:
  minReplicas: 3
  maxReplicas: 12
  scaleTargetRef: { apiVersion: apps/v1, kind: Deployment, name: api }
  metrics:
  - type: Resource
    resource: { name: cpu, target: { type: Utilization, averageUtilization: 65 } }
  behavior:
    scaleDown: { stabilizationWindowSeconds: 300 }

Security and change-control considerations

Autoscalers need scoped permissions to read metrics and change workloads or nodes. Protect metrics endpoints and avoid exposing tenant or sensitive identifiers in labels. Node provisioning policies should restrict instance types, subnets, security groups, and IAM roles. Capacity expansion must not silently bypass network, admission, or image-policy controls.

Performance, monitoring, and operational considerations

Investigate the full chain when scaling fails: metrics availability, HPA events, target requests, pending pods, node capacity, cloud quotas, image pulls, readiness failures, and downstream saturation. Alert on max-replica saturation, pending pods, unavailable replicas, repeated scaling events, and node-provisioning failures. Do not assume more pods help if the real bottleneck is a database connection pool, third-party API, or lock.

Production delivery and verification

Before changing a live $kubernetes autoscaling: hpa, vpa and cluster autoscaler explained design, record the current baseline: ownership, dependency map, service objective, capacity or policy limit, and the signals that would prove the change helped. A change without a baseline is difficult to validate and easy to misattribute after the next deployment or traffic shift.

Make the smallest reversible change first. Test it in a representative non-production environment, then release with a bounded blast radius, a named owner, and a rollback condition. Change windows are not a substitute for safety; the practical controls are an identified previous state, compatible data or configuration, and a clear decision point for stopping the rollout.

During and after release, correlate infrastructure signals with the user journey. Watch error rate, latency, saturation, availability, and the workload-specific signal that prompted the work. Record the observed outcome in the engineering decision log. This turns a one-off fix into operational knowledge that can be reused during planning, incident response, and the next review.

Finally, keep the runbook current. It should state what normal looks like, what breaks first, who owns the dependency, how to collect evidence, and which action is safe under pressure. Good documentation is concise enough to use during an incident and specific enough to prevent an unsafe guess.

Decision guidance

Use HPA for variable demand with a dependable metric, VPA cautiously when request tuning is hard, and node scaling when scheduler pressure requires capacity. Karpenter can reduce provisioning friction where its operational model fits. Keep the design simple enough that an on-call engineer can explain why a replica count changed and what constrains the next layer.

Related technical reading: ECS vs EKS: How to Choose the Right Container Platform · Cloud Monitoring Strategy: Metrics, Logs, Traces and Alerting

Practical implementation checklist

  1. Set realistic requests and limits before relying on autoscaling.
  2. Select a metric that predicts useful work and protects dependencies.
  3. Tune min/max replicas, stabilization, and startup behavior.
  4. Ensure node scaling and cloud quotas can satisfy pending pods.
  5. Test burst, sustained load, and recovery scenarios with dashboards and alerts.

Frequently asked questions

Why does HPA not add replicas?

Check Metrics Server or adapter data, HPA events, resource requests, target reference, and whether the metric is above the configured target.

Why are new pods pending?

They may exceed available node resources, violate affinity or topology constraints, await a volume, or be blocked by quota or node provisioning.

Can VPA and HPA be used together?

They can, but target choices must avoid conflicting control loops. Commonly HPA uses external metrics while VPA manages resource recommendations.

Need help improving your cloud infrastructure?

Talk to a VexEagle Engineer