Sub topic 10
Configuring the Cluster Autoscaler on AWS
This chapter assumes you know how the Cluster Autoscaler scales up and down, what expanders are, and how Auto Scaling groups (ASGs) back node groups. Here you wire those ideas into a working AWS configuration.
Discovering node groups
On AWS, the Cluster Autoscaler manages ASGs. You can list them by name, or let it find them by tag. Auto-discovery is easier to maintain, because new groups join automatically when they carry the right tags.
Tag each ASG you want managed with two keys:
k8s.io/cluster-autoscaler/enabledk8s.io/cluster-autoscaler/my-cluster
The autoscaler also needs IAM permissions to read and resize those groups. Grant them through IAM Roles for Service Accounts or EKS Pod Identity, not through the node role.
The container arguments
command:
- ./cluster-autoscaler
- --cloud-provider=aws
- --node-group-auto-discovery=asg:tag=k8s.io/cluster-autoscaler/enabled,k8s.io/cluster-autoscaler/my-cluster
- --expander=least-waste
- --balance-similar-node-groups
- --skip-nodes-with-system-pods=falseEach flag does one job:
| Flag | Effect |
|---|---|
| `--cloud-provider=aws` | Uses the AWS implementation to read and resize ASGs. |
| `--node-group-auto-discovery` | Manages every ASG that has both tags. |
| `--expander=least-waste` | Picks the group that leaves the least idle CPU and memory after scale-up. |
| `--balance-similar-node-groups` | Keeps groups with the same instance shape at similar sizes. |
| `--skip-nodes-with-system-pods=false` | Lets scale-down remove nodes that run kube-system pods. |
Balancing across zones
An ASG that spans several zones can scale unevenly. A common pattern is one ASG per zone with identical instance types and labels. With --balance-similar-node-groups, the autoscaler splits new nodes evenly across those groups. This matters for workloads that use topology spread constraints, and for volumes that are tied to one zone.
Checking that it works
Use the test Deployment from earlier chapters, then scale it up:
kubectl scale deployment inflate --replicas=10
kubectl get pods -l app=inflate
kubectl -n kube-system logs deployment/cluster-autoscaler | grep -i "scale-up"Pending pods should trigger a scale-up log line, and the ASG's desired capacity should rise. If it does not, check these in order:
- The ASG tags match the discovery flag exactly.
- The ASG's maximum size is above its current size.
- The IAM role allows
autoscaling:SetDesiredCapacityandautoscaling:DescribeAutoScalingGroups. - The pod's selectors and tolerations match at least one discovered group.
Exercise
Pods stay Pending, and the autoscaler logs show no scale-up attempt. The ASG has the tag k8s.io/cluster-autoscaler/enabled but no cluster-specific tag. What is the likely cause, and how do you fix it?
Show answer
The discovery flag lists both tags, and an ASG must have both to be managed. Without the k8s.io/cluster-autoscaler/my-cluster tag, the autoscaler ignores the group. Add the second tag to the ASG, and the next scan should find it.