Amazon EKS — Cluster Autoscaler
Cluster Autoscaler
When HPA adds more pods but there’s no room on existing nodes, Cluster Autoscaler adds more nodes to the cluster.
How It Works
Cluster Autoscaler Flow
┌─────────────────────────────────────────────────────┐
│ │
│ 1. Pod is Pending (insufficient resources) │
│ 2. Cluster Autoscaler detects pending pods │
│ 3. Evaluates which node group can fit the pod │
│ 4. Increases ASG desired count │
│ 5. New node registers with cluster │
│ 6. Pod scheduled on new node │
│ │
│ Scale Down: │
│ 1. Node utilization < 50% for 10 minutes │
│ 2. All pods can be moved to other nodes │
│ 3. Node cordoned, pods drained, node terminated │
│ │
└─────────────────────────────────────────────────────┘
Install Cluster Autoscaler
# Step 1: Create IRSA
$ eksctl create iamserviceaccount \
--cluster demo \
--name cluster-autoscaler \
--namespace kube-system \
--attach-policy-arn arn:aws:iam::123456789012:policy/ClusterAutoscalerPolicy \
--approve
# Step 2: Deploy
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml
# Step 3: Add cluster name annotation
$ kubectl -n kube-system annotate deployment.apps/cluster-autoscaler \
cluster-autoscaler.kubernetes.io/safe-to-evict="false"
Configuration
# Key flags for Cluster Autoscaler
--balance-similar-node-groups=true # Balance across AZs
--skip-nodes-with-local-storage=false # Allow scale down of nodes with emptyDir
--expander=least-waste # Efficient node selection
--scale-down-utilization-threshold=0.5 # Scale down if < 50% utilized
--scale-down-delay-after-add=10m # Wait 10 min after adding a node
Common Mistakes
| Mistake | Impact |
|---|---|
| Missing ASG tags | Autoscaler can’t find node groups |
| maxSize too low | Can’t scale enough during peaks |
Not using --balance-similar-node-groups |
Uneven AZ distribution |
| PodDisruptionBudgets blocking scale-down | Nodes can’t be drained |
What’s Next?
The modern alternative: Karpenter.