Sub topic 7
Choosing a node group with expanders
This chapter assumes you know how the Cluster Autoscaler (CA) scales up. When pods are Pending, it simulates adding a node to each node group that could fit them. If more than one group works, an expander picks the winner. You also need basic familiarity with AWS Auto Scaling groups (ASGs) and the pod resource requests covered earlier.
What an expander does
An expander is a strategy that chooses one node group from the valid options. It runs only after CA has filtered out groups that cannot help, for example groups at their maximum size or groups whose nodes do not match the pod's selectors. You set the strategy with the --expander flag.
Common expanders
| Expander | Choice it makes | Typical use |
|---|---|---|
| `random` | A random valid group (the default) | Simple clusters with one group |
| `most-pods` | The group that schedules the most pending pods | Mixed pod sizes, many groups |
| `least-waste` | The group with the least idle CPU and memory after scheduling | Cost control with different instance sizes |
| `price` | The cheapest option (GCE only) | Not available on AWS |
| `priority` | The group ranked highest in a ConfigMap | Prefer spot, fall back to on-demand |
You can combine expanders in a comma-separated list, such as --expander=priority,least-waste. CA applies them in order, and each one narrows the candidates until a single group remains.
Example: least-waste
The AWS configuration from the spine uses least-waste:
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=falseSuppose three pods each request 1 CPU and 1Gi, and you have a 2-CPU group and a 16-CPU group. A 2-CPU node fits two pods, but a 16-CPU node would leave most of its capacity idle. least-waste computes the unused share for each candidate and prefers the better fit.
The --balance-similar-node-groups flag works alongside the expander. When several groups have the same instance type and labels, such as one per availability zone, CA spreads new nodes across them instead of filling one.
The priority expander
The priority expander reads a ConfigMap named cluster-autoscaler-priority-expander in kube-system. Higher numbers win, and each value is a list of regular expressions matched against node group names.
apiVersion: v1
kind: ConfigMap
metadata:
name: cluster-autoscaler-priority-expander
namespace: kube-system
data:
priorities: |-
50:
- .*spot.*
10:
- .*on-demand.*CA tries spot groups first. If spot capacity is unavailable, a later scale-up attempt can fall back to on-demand groups.
Common mistakes
- Expecting an expander to override constraints. It only chooses among groups that already pass the filters, so a pod with an impossible node selector stays Pending whatever you set.
- Using
priceon AWS. It is not supported there. - Misspelling the ConfigMap name or namespace. CA then has no priorities to apply.
- Using
most-podsand ignoring cost, since it can pick large, expensive nodes.
Exercise
Your cluster has a spot node group and an on-demand node group. You want CA to prefer spot, and to use least-waste to break ties between several spot groups. How do you configure the expander?
Show answer
Set --expander=priority,least-waste. Create the cluster-autoscaler-priority-expander ConfigMap in kube-system with a higher priority for the spot group names, such as 50: [.*spot.*] and 10: [.*on-demand.*]. The priority expander narrows the candidates to the highest-ranked groups, and least-waste picks among any that remain.