Sub topic 15
Consolidation, drift, expiration and disruption budgets
This chapter assumes you know NodePools and EC2NodeClasses, how Karpenter launches nodes, and how PodDisruptionBudgets work. It covers how Karpenter removes or replaces nodes after they are running.
Four ways Karpenter disrupts nodes
Karpenter treats node removal as "disruption". It has four reasons to disrupt a node.
| Reason | Trigger | Replaces node? |
|---|---|---|
| Consolidation (empty) | Node has no non-daemon pods | No |
| Consolidation (underutilized) | Pods fit on other nodes, or on one cheaper node | Sometimes |
| Drift | Node no longer matches its NodePool or EC2NodeClass | Yes |
| Expiration | Node is older than `expireAfter` | Yes |
Karpenter always creates replacement capacity first when pods need it. It then taints the node, evicts pods, and deletes the instance.
Consolidation
The consolidationPolicy field sets what Karpenter may consolidate:
WhenEmptyremoves only nodes with no workload pods.WhenEmptyOrUnderutilizedalso deletes a node when its pods fit elsewhere, or replaces it with a cheaper node.
The consolidateAfter field is how long a node must stay quiet before Karpenter acts on it. The NodePool from earlier chapters uses 1m. A longer value reduces churn in clusters where pods come and go often.
Drift and expiration
A node drifts when its configuration differs from the desired one. Examples are a changed NodePool requirement or a newer AMI chosen by al2023@latest. Karpenter replaces drifted nodes gradually, which gives you rolling AMI upgrades.
expireAfter: 720h forces every node to be replaced after 30 days. This keeps nodes patched and prevents long-lived nodes from accumulating problems.
Disruption budgets
A budget limits how many nodes Karpenter disrupts at once. It is set under spec.disruption in the NodePool. This example allows 10% of nodes to be disrupted at a time. It blocks all disruption on weekdays from 09:00 UTC for 8 hours.
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
name: default
spec:
template:
spec:
nodeClassRef:
group: karpenter.k8s.aws
kind: EC2NodeClass
name: default
disruption:
consolidationPolicy: WhenEmptyOrUnderutilized
consolidateAfter: 1m
budgets:
- nodes: "10%"
- nodes: "0"
schedule: "0 9 * * mon-fri"
duration: 8hWhen several budgets are active, the strictest one applies. You can add a reasons list (such as Drifted or Underutilized) to target a budget at one cause.
Protecting workloads
Budgets limit nodes. PodDisruptionBudgets limit pods. Karpenter respects PDBs while draining, so a PDB like minAvailable: 2 slows eviction. A PDB that can never be satisfied can block a node indefinitely.
To exempt a pod, add the annotation karpenter.sh/do-not-disrupt: "true". Karpenter will not voluntarily disrupt its node while the pod runs. You can set the same annotation on a node.
Common errors
- Consolidation never happens because pods have high requests or strict anti-affinity, so they cannot fit elsewhere.
- Nodes churn constantly because
consolidateAfteris too short. - Upgrades stall because a PDB allows zero disruptions.
Exercise
A NodePool has a budget of nodes: "0" with a weekday 09:00 schedule lasting 8h, plus nodes: "10%". A node passes expireAfter at 10:00 on a Tuesday. What does Karpenter do?
Show answer
It waits. The strictest active budget (0 nodes) applies, so the expired node is not disrupted until the window ends at 17:00. Then the 10% budget lets it be replaced.