Skip to content

05 · The NodePools: the disruption contracts

Goal: two NodePools on the same NodeClass that make opposite promises. One holds capacity steady and changes only on your terms; the other appears on demand, runs on Spot, and disappears as soon as the work is done.

stable-static: "never disrupt this"

manifests/20-nodepool-stable-static.yaml
# "Never disrupt this": the always-on tier.
# Walkthrough: docs/05-nodepools.md
#
# Static capacity: exactly N nodes, whether or not pods ask for them.
# Static pools are never consolidated and can't carry a `weight`.
#
# BUT: Auto Mode still replaces these nodes. Every node has a 21-day maximum
# lifetime, and nodes drift when a new AMI ships (roughly weekly) or when the
# NodeClass changes. "Never disrupt" really means "disrupt only on my terms",
# hence the budgets below, plus a PDB on the workload.
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: stable-static
  labels:
    talk: mastering-custom-node-pools
spec:
  replicas: 2                        # fixed node count; once set, can't be removed
  limits:
    # Keep above replicas: drift launches the replacement before it
    # removes the old node, and needs headroom to do so.
    nodes: 3

  disruption:
    # Auto Mode requires this field whenever `disruption` is set. Static
    # pools are never consolidated anyway; Never says so explicitly.
    consolidateAfter: Never
    budgets:
      - nodes: "1"                   # always: never more than one node at a time
      - nodes: "0"                   # business hours: no drift replacements
        reasons: ["Drifted"]
        schedule: "0 20 * * sun-thu" # cron is UTC: 20:00 UTC = 09:00 NZDT, Mon-Fri
        duration: 8h                 # until 17:00 NZDT. CHANGE ME for your timezone

  template:
    metadata:
      labels:
        workload-tier: stable
    spec:
      nodeClassRef:
        group: eks.amazonaws.com
        kind: NodeClass
        name: demo-default
      # Auto Mode's hard cap is 21 days (504h); the built-in pools use 14 (336h).
      # Expiry is forceful: budgets don't hold it back. PDBs are honoured
      # until terminationGracePeriod runs out.
      expireAfter: 480h
      terminationGracePeriod: 24h
      taints:
        - key: workload-tier
          value: stable
          effect: NoSchedule
      requirements:
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["on-demand"]
        - key: eks.amazonaws.com/instance-category
          operator: In
          values: ["m"]
        - key: eks.amazonaws.com/instance-generation
          operator: Gt
          values: ["5"]
        - key: eks.amazonaws.com/instance-cpu
          operator: In
          values: ["2", "4"]
        - key: kubernetes.io/arch
          operator: In
          values: ["amd64"]

Line by line:

  • replicas: 2 makes this a static capacity pool: exactly two nodes, whether or not any pod asks for them. No cold start for the service that lives here. Once set, replicas can't be removed; a pool is static or dynamic for life.
  • No weight, no consolidationPolicy. Static pools are never considered for consolidation, and weight isn't allowed on them, because they never take part in "which pool should this pod go to" ordering. Only limits.nodes applies to a static pool (not CPU or memory).
  • consolidateAfter: Never: Auto Mode requires consolidateAfter whenever a disruption block exists. Leave it out and the API server rejects the pool with spec.disruption.consolidateAfter: Required value. Never states the truth for a static pool. (Auto Mode also fills in consolidationPolicy: Balanced on the live object; it has no effect here.)
  • limits.nodes: 3, deliberately one above replicas. Drift replacement launches the new node before removing the old one. If the limit equalled replicas, there'd be no room for the replacement and drifted nodes would get stuck.

"Never" doesn't mean never. Static nodes are still replaced:

  • Every Auto Mode node has a 21-day maximum lifetime. expireAfter: 480h (20 days) puts expiry just under that cap, versus the 336h (14 days) the built-in pools use. Expiry is forceful: disruption budgets don't hold it back. PDBs are honoured until terminationGracePeriod (24h here) runs out, then the node goes anyway.
  • Nodes drift when a new Auto Mode AMI ships (roughly weekly) or when the NodeClass changes. Drift is governed by budgets, so:
Budget Effect
nodes: "1" Always on: never more than one node disrupted at a time. Without it, outside the window nothing limits how many drift at once.
nodes: "0", reasons: ["Drifted"], schedule: "0 20 * * sun-thu", duration: 8h During business hours, zero drift replacements.

When several budgets apply, the most restrictive one wins.

Budget schedules are always UTC

0 20 * * sun-thu is 20:00 UTC Sunday to Thursday, which is 09:00 Monday to Friday in Wellington under NZDT (UTC+13). The window lasts 8h, until 17:00. Under NZST (UTC+12) it's an hour early. Convert your own business hours to UTC and edit the cron. Note how the day range shifts when the UTC time crosses midnight.

The third leg is the PodDisruptionBudget on the workload in step 06: it makes each replacement survivable, one pod at a time.

  • taints: workload-tier=stable:NoSchedule keeps everything out unless it explicitly tolerates it.
  • requirements: on-demand only, m family, generation 6 or newer, 2 or 4 vCPU, x86. Narrow on purpose: predictable capacity for a predictable service.

spot-burst: "burst and save"

manifests/21-nodepool-spot-burst.yaml
# "Burst and save": the elastic tier.
# Same NodeClass as stable-static. Different disruption contract.
# Walkthrough: docs/05-nodepools.md
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: spot-burst
  labels:
    talk: mastering-custom-node-pools
spec:
  limits:
    cpu: "64"                        # spend ceiling for the whole pool

  disruption:
    # On EKS 1.37, new Auto Mode NodePools that omit consolidationPolicy
    # default to Balanced. Set it explicitly anyway: defaults change, and
    # YAML in Git shouldn't depend on which version created it.
    consolidationPolicy: Balanced    # weigh savings against disruption cost
    consolidateAfter: 1m
    budgets:
      - nodes: "30%"

  template:
    metadata:
      labels:
        workload-tier: burst
    spec:
      nodeClassRef:
        group: eks.amazonaws.com
        kind: NodeClass
        name: demo-default
      expireAfter: 168h
      terminationGracePeriod: 30m
      taints:
        - key: workload-tier
          value: burst
          effect: NoSchedule
      requirements:
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["spot"]
        # Breadth is the reliability lever for Spot: the wider this is,
        # the more capacity pools there are to fall back to on reclaim.
        - key: eks.amazonaws.com/instance-category
          operator: In
          values: ["c", "m", "r"]
        - key: eks.amazonaws.com/instance-generation
          operator: Gt
          values: ["5"]
        - key: eks.amazonaws.com/instance-cpu
          operator: In
          values: ["2", "4", "8"]
        - key: kubernetes.io/arch
          operator: In
          values: ["amd64", "arm64"]
  • capacity-type: spot across c, m and r, generation 6+, 2–8 vCPU, both x86 and Graviton. Breadth is the reliability lever for Spot: each combination is a separate capacity pool to fall back on when one is reclaimed. A narrow Spot pool is an unreliable one.
  • consolidationPolicy: Balanced: scores each consolidation move by savings versus disruption cost, and skips the marginal ones. It's the default for new pools on EKS 1.37, but set it explicitly: defaults change, and YAML in Git shouldn't behave differently depending on which version created the object.
  • consolidateAfter: 1m: a node has to sit unchanged for a minute before it's a consolidation candidate. Short, because burst capacity should leave fast.
  • budgets: 30%: up to 30% of the pool's nodes may be disrupted at once.
  • limits.cpu: "64": the spend ceiling. Auto Mode won't launch more than 64 vCPU in this pool, however many pods are pending.
  • expireAfter: 168h: Spot nodes shouldn't live long anyway.
  • taints: only workloads that opt in to workload-tier=burst land here.

Apply them

Dry run first:

kubectl apply --dry-run=server \
  -f manifests/20-nodepool-stable-static.yaml \
  -f manifests/21-nodepool-spot-burst.yaml
nodepool.karpenter.sh/stable-static created (server dry run)
nodepool.karpenter.sh/spot-burst created (server dry run)

Then apply, and create the namespace the workloads will use:

manifests/00-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: demo-nodepools
  labels:
    talk: mastering-custom-node-pools
kubectl apply -f manifests/00-namespace.yaml
kubectl apply -f manifests/20-nodepool-stable-static.yaml -f manifests/21-nodepool-spot-burst.yaml
kubectl get nodepools

All four pools are listed: the two built-ins on default, and our two on demo-default.

Watch the static nodes appear

No pod has asked for anything, yet two nodes start launching. That's static capacity: set, not demanded.

kubectl get nodeclaims -w

Each NodeClaim goes from launched to registered to initialized, usually in under a minute. Press Ctrl+C when both show READY True. Then:

kubectl get nodes -L karpenter.sh/nodepool,karpenter.sh/capacity-type,node.kubernetes.io/instance-type

From a test run:

NAME                  STATUS   ROLES    AGE     VERSION               NODEPOOL        CAPACITY-TYPE   INSTANCE-TYPE
i-0123456789abc0002   Ready    <none>   7s      v1.37.0-eks-29d7970   stable-static   on-demand       m6a.large
i-0123456789abc0003   Ready    <none>   7s      v1.37.0-eks-29d7970   stable-static   on-demand       m6a.large
i-0123456789abc0005   Ready    <none>   5m26s   v1.37.0-eks-29d7970   system          on-demand       c6g.large
i-0123456789abc0006   Ready    <none>   5m27s   v1.37.0-eks-29d7970   system          on-demand       c6g.large

(Instance types will vary; anything m, gen 6+, 2–4 vCPU, x86.) Two static nodes, zero pods asking for them. The spot-burst pool has nothing yet: it waits for demand. Auto Mode names nodes after their EC2 instance IDs.

Not evenly spread

In the test run both static nodes landed in the same AZ. AWS documents that a multi-AZ static pool's distribution isn't guaranteed to be even. For a predictable spread, use one static pool per AZ, each pinned with a topology.kubernetes.io/zone requirement.

Confirm the pool's own count matches replicas:

kubectl get nodepool stable-static -o jsonpath='{.status.nodes}{"\n"}'

Confirm your tags reached EC2:

aws ec2 describe-instances \
  --filters "Name=tag:Talk,Values=mastering-custom-node-pools" "Name=instance-state-name,Values=running" \
  --query 'Reservations[].Instances[].{id: InstanceId, type: InstanceType, publicIp: PublicIpAddress, owner: Tags[?Key==`Owner`]|[0].Value}' \
  --output table
+----------------------+------------+-----------+-------------+
|          id          |   owner    | publicIp  |    type     |
+----------------------+------------+-----------+-------------+
|  i-0123456789abc0003 |  your-name |  None     |  m6a.large  |
|  i-0123456789abc0002 |  your-name |  None     |  m6a.large  |
+----------------------+------------+-----------+-------------+

Your tags are on the instances, and publicIp is None: that's associatePublicIPAddress: false at work.

Nodes not appearing? See Troubleshooting.

Next: 06 Workloads.