Kubernetes VPA and Cluster Autoscaler

The Horizontal Pod Autoscaler adds more pods when load grows. Two gaps remain: pods may request the wrong amount of CPU and memory, and the cluster may run out of room for new pods. The Vertical Pod Autoscaler (VPA) fixes the first gap. The Cluster Autoscaler fixes the second.

The Moving Day Analogy

Picture a family moving into a rented house. HPA hires more family members to share chores. VPA measures how much room each person really needs and adjusts the bedroom size. Cluster Autoscaler rents an extra house when the current one fills up and returns an empty house when nobody uses it.

Vertical Pod Autoscaler

Developers often guess resource requests. A guess that runs too high wastes money, and a guess that runs too low causes throttling or out-of-memory kills. VPA watches real usage and recommends better numbers.

VPA Components

  • Recommender studies usage history and calculates ideal requests.
  • Updater evicts pods whose requests differ too far from the recommendation.
  • Admission controller sets the new requests when the replacement pod starts.

VPA ships as an add-on project, so install it before use.

Writing a VPA Object

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: orders-vpa
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: orders
  updatePolicy:
    updateMode: "Off"
  resourcePolicy:
    containerPolicies:
    - containerName: "*"
      minAllowed:
        cpu: 100m
        memory: 128Mi
      maxAllowed:
        cpu: "2"
        memory: 2Gi

Update Modes

ModeBehavior
OffCalculates recommendations only. No pod changes.
InitialApplies values only when new pods start.
RecreateEvicts running pods to apply new values.
AutoChooses the best available update method.

Start with Off. Read the suggestions with kubectl describe vpa orders-vpa and copy sensible values into your deployment manually. This approach builds trust before automation touches production pods.

VPA and HPA Together

Never let both autoscalers react to the same CPU or memory metric. They fight each other: HPA adds pods while VPA resizes them. Pair VPA with HPA only when HPA scales on a custom or external metric such as requests per second.

Cluster Autoscaler

Pods need nodes. When a pod stays in Pending state because no node has enough free CPU or memory, the Cluster Autoscaler asks the cloud provider for another node. When a node stays mostly idle, it drains the node and removes it.

Diagram: Scale-Up Flow

 HPA adds pods
      │
      ▼
 New pod cannot fit ──▶ status: Pending
      │
      ▼
 Cluster Autoscaler notices pending pod
      │
      ▼
 Requests new node from node group
      │
      ▼
 Node joins cluster ──▶ scheduler places pod ──▶ Running

Diagram: Scale-Down Flow

 Node usage below threshold for 10 minutes
      │
      ▼
 Autoscaler checks that pods can move elsewhere
      │
      ▼
 Drains the node (pods reschedule)
      │
      ▼
 Cloud provider deletes the node

The default utilization threshold is 50 percent of requested resources, and the default wait is 10 minutes. Administrators tune both values with flags.

What Blocks Scale-Down

  • Pods with local storage that the autoscaler cannot move.
  • Pods with strict PodDisruptionBudgets.
  • Pods that carry the annotation cluster-autoscaler.kubernetes.io/safe-to-evict: "false".
  • Pods without a controller, such as a bare pod created by hand.

Setting It Up

Managed services (GKE, EKS, AKS) offer node pool autoscaling with a few settings. Self-managed clusters deploy the Cluster Autoscaler as a pod and give it permission to resize cloud node groups. Each node group has a minimum and maximum size.

--nodes=2:10:worker-group-1
--scale-down-utilization-threshold=0.5
--scale-down-unneeded-time=10m

Karpenter is a newer alternative that picks node sizes pod by pod and skips fixed node groups. Teams on AWS often choose it for faster scaling and tighter cost control.

Requests Drive Everything

Both autoscalers rely on resource requests, not live usage, to make decisions. A pod without requests looks free to the scheduler and breaks capacity planning. Define requests for every container, and let VPA help tune them.

Key Points

  • VPA adjusts pod size; HPA adjusts pod count.
  • Cluster Autoscaler adds and removes nodes to fit pending pods.
  • Start VPA in Off mode and review recommendations.
  • Accurate resource requests keep all three autoscalers effective.