Sub topic 3
Scheduling constraints that shape node choice
This chapter assumes you know Pods, Deployments and Nodes, how resource requests work, and how to read a Pending pod's events with kubectl describe. The previous chapter showed that a node autoscaler reacts to Pending pods. This chapter covers a second question: which nodes may a pod run on? An autoscaler only helps if the node it adds satisfies the pod's constraints.
Why constraints matter to autoscalers
The scheduler places a pod only on a node that passes every constraint. If no existing node passes, the pod stays Pending. A node autoscaler then simulates adding a node and checks whether the pod would fit. If the pod's constraints rule out every node the autoscaler could create, no scale-up happens.
The main constraints
| Constraint | What it does | Effect on autoscaling |
|---|---|---|
| `nodeSelector` | Requires node labels to match exactly | Needs a node group or NodePool that produces nodes with that label |
| Node affinity | Label rules with operators such as `In` and `NotIn`, either required or preferred | Required rules limit which groups qualify. Preferred rules are only hints |
| Taints and tolerations | A taint repels pods unless they tolerate it | A tainted group only helps pods that tolerate the taint |
| Pod anti-affinity | Keeps pods apart, for example one per node | Can force one new node for each pod |
| Topology spread | Balances pods across zones or nodes | Can require capacity in a specific zone |
A worked example
This pod requires a GPU node label and tolerates a matching taint.
apiVersion: v1
kind: Pod
metadata:
name: trainer
spec:
nodeSelector:
workload: gpu
tolerations:
- key: dedicated
operator: Equal
value: gpu
effect: NoSchedule
containers:
- name: trainer
image: registry.k8s.io/pause:3.9
resources:
requests:
cpu: "2"
memory: 4GiIf no node group has the label workload: gpu, the pod stays Pending and the Cluster Autoscaler logs that no node group could help. Karpenter behaves the same way when no NodePool allows that label.
Common errors
- Label mismatch. The pod selects a label that no node group or NodePool produces. With the Cluster Autoscaler, the label must be on the group's launch template or node template.
- Missing toleration. A node group has a taint and the pod has no matching toleration, so the new nodes are useless to that pod.
- Zone-bound volumes. A pod using a zonal volume can only run in that volume's zone. The group you scale must exist in that zone.
- Strict topology spread. With
whenUnsatisfiable: DoNotSchedule, a pod can stay Pending even when other zones have free space. - Anti-affinity at scale. Required anti-affinity across many replicas causes one node per replica, which is costly and can reach node limits.
Exercise
A Deployment's pods have nodeSelector: {disktype: ssd}. They are Pending, and the cluster has three node groups, none labeled disktype=ssd. Will the Cluster Autoscaler add nodes? What would you change?
Show answer
No. No node group would produce a node that satisfies the selector, so adding nodes cannot help. Either add the label disktype=ssd to the node template of a suitable node group (or to a Karpenter NodePool's requirements), or remove the selector if the pods do not need SSD nodes.