Kubernetes Autoscaling: HPA, VPA, Cluster Autoscaler and KEDA

Scale Kubernetes workloads automatically: Horizontal Pod Autoscaler on CPU and custom metrics, VPA, node autoscaling with Cluster Autoscaler or Karpenter.

Published December 2, 2026

Traffic is rarely flat. Autoscaling lets Kubernetes add capacity when demand rises and remove it when demand falls, saving money and protecting performance. There are several autoscalers, each working at a different level, and they are most effective when combined deliberately.

The concept

The Horizontal Pod Autoscaler (HPA) changes the number of pod replicas based on metrics: CPU or memory utilisation relative to requests, or custom and external metrics like requests per second or queue length. The Vertical Pod Autoscaler (VPA) adjusts pod requests and limits instead, mainly useful for right-sizing. KEDA extends HPA with event-driven scalers (Kafka lag, RabbitMQ queue depth, cron schedules) and can scale deployments to zero.

Pods need nodes. When new replicas cannot be scheduled, the Cluster Autoscaler (or Karpenter on AWS and other providers) adds nodes, and removes underused nodes later. Because HPA utilisation is calculated against requests, accurate resource requests are a prerequisite for sensible autoscaling.

The autoscaling stack

KEDAevent-driven scaling, scale to zeroHPAmore/fewer pods from metricsVPAright-size pod requestsCluster Autoscaler / Karpenteradd/remove nodes
Autoscalers at different levels.

Scaling in action

Metrics serverHPADeploymentNode autoscalerread CPU: 85% of requestsscale 4 → 7 replicas2 pods pending (no room)provision nodepods scheduled, running
Pod autoscaling triggers node autoscaling when the cluster is full.

Why autoscale

Fixed 10 replicas (24h)240 pod-hoursHPA 2-10 replicas≈110 pod-hours
Illustrative daily capacity for a service with daytime peaks.

Practical examples

HPA on CPU utilisation

autoscaling/v2 with stabilisation to avoid flapping.

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

KEDA: scale workers on queue length

Scale to zero when the queue is empty.

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata: { name: email-worker }
spec:
  scaleTargetRef: { name: email-worker }
  minReplicaCount: 0
  maxReplicaCount: 30
  triggers:
    - type: rabbitmq
      metadata: { queueName: emails, mode: QueueLength, value: "50" }
      authenticationRef: { name: rabbitmq-auth }

Watch the HPA decide

Current vs target metrics and replica count.

kubectl get hpa api -w
kubectl describe hpa api | tail -15

Common mistakes

  • HPA on CPU without resource requests (utilisation cannot be calculated).
  • Running HPA and VPA on the same CPU/memory metric, fighting each other.
  • maxReplicas so high that a bug or attack scales costs unboundedly.
  • Scaling on CPU for I/O-bound services where queue length or RPS is the real signal.

Key takeaways

  • HPA scales pods, VPA sizes pods, node autoscalers add nodes, KEDA adds event triggers.
  • Accurate requests are required for utilisation-based scaling.
  • Scale on the metric that reflects real load.
  • Set sensible min/max and scale-down stabilisation.

FAQ

How fast does HPA react?

It evaluates metrics roughly every 15 seconds by default; adding new nodes can take a minute or more, so keep some headroom.

Can I scale to zero with plain HPA?

Standard HPA keeps at least one replica; KEDA or Knative support scale to zero.

What metrics adapter do I need for custom metrics?

Something that implements the custom/external metrics APIs, such as Prometheus Adapter, KEDA or a cloud provider adapter.

More DevOps articles