Cluster Autoscaler

The Cluster Autoscaler adds and removes nodes so pending pods get capacity and idle nodes are removed.

The Cluster Autoscaler watches for pods that can't be scheduled because there isn't enough room, and grows the node group's Auto Scaling group to fit them. When nodes sit underused, it scales back down.

How it decides

  • Scale up — a pod is Pending due to insufficient CPU/memory, so the autoscaler increases the desired node count.
  • Scale down — a node's pods can fit elsewhere, so it drains and removes the node.

It works at the node-group level and needs the group's min/max sizes tagged so it knows the allowed range.

Example

Example · bash
# Node group ASGs must carry these tags for auto-discovery
#   k8s.io/cluster-autoscaler/enabled
#   k8s.io/cluster-autoscaler/demo

kubectl -n kube-system logs deploy/cluster-autoscaler | tail -n 20
kubectl get pods --field-selector=status.phase=Pending

When to use it

  • An e-commerce platform configures the Cluster Autoscaler so nodes are added automatically during Black Friday traffic surges without manual intervention.
  • A data pipeline team sets scale-down-delay to 10 minutes so nodes are not removed between short batch job waves that would cause repeated scale-up/down cycles.
  • A cost optimization team enables expander=least-waste so the Cluster Autoscaler selects the node group that wastes the fewest unallocated resources when scaling up.

More examples

Deploy Cluster Autoscaler

Installs the Cluster Autoscaler via Helm with auto-discovery mode, finding node groups tagged with the cluster name automatically.

Example · bash
helm repo add autoscaler https://kubernetes.github.io/autoscaler
helm install cluster-autoscaler autoscaler/cluster-autoscaler \
  --namespace kube-system \
  --set autoDiscovery.clusterName=prod \
  --set awsRegion=us-east-1 \
  --set rbac.serviceAccount.create=false \
  --set rbac.serviceAccount.name=cluster-autoscaler

Tag node group for auto-discovery

Adds the required auto-discovery tags to the ASG so the Cluster Autoscaler can find and manage this node group.

Example · bash
aws autoscaling create-or-update-tags \
  --tags \
    ResourceId=prod-workers-asg,ResourceType=auto-scaling-group,Key=k8s.io/cluster-autoscaler/enabled,Value=true,PropagateAtLaunch=false \
    ResourceId=prod-workers-asg,ResourceType=auto-scaling-group,Key=k8s.io/cluster-autoscaler/prod,Value=owned,PropagateAtLaunch=false

View autoscaler scaling decisions

Tails the Cluster Autoscaler logs and filters for scale-up and scale-down events to understand why nodes were added or removed.

Example · bash
kubectl logs -n kube-system \
  -l app.kubernetes.io/name=cluster-autoscaler \
  --tail=50 | grep -E 'scale|node'

Discussion

  • Be the first to comment on this lesson.