Skip to content

09 · Optional labs

Each lab stands on its own, starts from the end of step 08, and finishes with its own undo. Do any, all or none.

Lab 1: break it, and read the event

A worker that targets the Spot pool with a nodeSelector, but forgot the toleration: only one of the two halves.

labs/40-orphan-worker.yaml
# Lab: break it on purpose. Selects the Spot pool but has NO toleration
# for its taint, so it sits Pending until you patch one in.
# Walkthrough: docs/09-optional-labs.md
apiVersion: apps/v1
kind: Deployment
metadata:
  name: orphan-worker
  namespace: demo-nodepools
  labels:
    app: orphan-worker
spec:
  replicas: 1
  selector:
    matchLabels:
      app: orphan-worker
  template:
    metadata:
      labels:
        app: orphan-worker
    spec:
      nodeSelector:
        workload-tier: burst
      # tolerations: <- missing on purpose
      containers:
        - name: worker
          image: public.ecr.aws/docker/library/busybox:1.36
          command: ["sh", "-c", "echo 'finally scheduled'; sleep 3600"]
          resources:
            requests:
              cpu: 250m
              memory: 128Mi
kubectl apply -f labs/40-orphan-worker.yaml
kubectl -n demo-nodepools get pods -l app=orphan-worker

It sits Pending. Its nodeSelector rules out every node except spot-burst ones; the spot-burst taint rules those out; and Auto Mode can't launch a new Spot node for it, because the pod doesn't tolerate that pool's taint either.

Read why, and who said so:

POD=$(kubectl -n demo-nodepools get pods -l app=orphan-worker -o jsonpath='{.items[0].metadata.name}')
kubectl -n demo-nodepools get events --field-selector "involvedObject.name=$POD" \
  -o custom-columns='SOURCE:.source.component,REPORTER:.reportingComponent,REASON:.reason,MESSAGE:.message'
SOURCE                  REPORTER                REASON             MESSAGE
default-scheduler       default-scheduler       FailedScheduling   0/4 nodes are available: 4 node(s) had untolerated taint(s). ...
eks-auto-mode/compute   eks-auto-mode/compute   FailedScheduling   Failed to schedule pod, did not tolerate taint (taint=CriticalAddonsOnly:NoSchedule); did not tolerate taint (taint=workload-tier=burst:NoSchedule); incompatible requirements, label "workload-tier" does not have known values

The scheduler says no existing node fits. The Auto Mode compute controller says why no new node can be launched either: the pod doesn't tolerate the spot-burst taint, and no other pool offers workload-tier: burst. Look at the source: eks-auto-mode/compute, not karpenter. AWS renamed it in September 2025.

Count events across the cluster by both names:

kubectl get events -A -o json | jq '{
  karpenter: [.items[] | select((.source.component // .reportingComponent // "") == "karpenter")] | length,
  eks_auto_mode: [.items[] | select((.source.component // .reportingComponent // "") | startswith("eks-auto-mode"))] | length
}'

You'll see both names. Break the karpenter ones down by reason:

kubectl get events -A -o json | jq -r '[.items[] | select((.source.component // .reportingComponent // "") == "karpenter") | .reason] | group_by(.) | map("\(.[0]) \(length)") | .[]'

They're all status-condition transitions (Ready, Launched, Registered, Drained, …). Every decision, whether scheduling failures, nominations, disruptions or terminations, comes from eks-auto-mode/compute.

The alerting gotcha

An alert, dashboard or grep that filters on source=karpenter still sees events, so it doesn't look broken. But since the rename it only sees status flips. Every scheduling failure and disruption decision, the things you actually alert on, now arrives as eks-auto-mode/compute.

Fix it by adding the missing half:

kubectl -n demo-nodepools patch deployment orphan-worker --type=json -p='[
  {"op": "add", "path": "/spec/template/spec/tolerations", "value": [
    {"key": "workload-tier", "operator": "Equal", "value": "burst", "effect": "NoSchedule"}]}]'
kubectl -n demo-nodepools rollout status deploy/orphan-worker --timeout=240s
kubectl -n demo-nodepools get pods -l app=orphan-worker -o wide

Auto Mode launches a Spot node and the pod lands on it (about 30 seconds in the test run).

Undo:

kubectl delete -f labs/40-orphan-worker.yaml

The Spot node is consolidated away a minute or so later.

Lab 2: weight fall-through

When a pending pod fits more than one pool, weight decides the order: highest first, and when that pool hits its limits, the next one.

labs/nodepools-weighted.yaml
# Lab: weight fall-through ("When Several Pools Match").
# Walkthrough: docs/09-optional-labs.md
#
# Pods that select workload-tier=priority-demo match BOTH pools.
# graviton-first (weight 100) is tried first; once its 8 vCPU limit is used
# up, scheduling falls through to x86-spill (weight 10).
#
# Both pools are tainted so that ONLY the lab workload lands here. Without
# the taint, a weight-100 pool with broad requirements would also attract
# every other unselected pod in the cluster: overlap needs a decision.
#
# Swap the arm64 requirement for capacity-type "reserved" plus a NodeClass
# with capacityReservationSelectorTerms to get "use what you prepaid first".
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: graviton-first
  labels:
    talk: mastering-custom-node-pools
spec:
  weight: 100
  limits:
    cpu: "8"
  template:
    metadata:
      labels:
        workload-tier: priority-demo
    spec:
      nodeClassRef:
        group: eks.amazonaws.com
        kind: NodeClass
        name: demo-default
      taints:
        - key: workload-tier
          value: priority-demo
          effect: NoSchedule
      requirements:
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["on-demand"]
        - key: kubernetes.io/arch
          operator: In
          values: ["arm64"]
        - key: eks.amazonaws.com/instance-category
          operator: In
          values: ["c", "m"]
---
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: x86-spill
  labels:
    talk: mastering-custom-node-pools
spec:
  weight: 10
  limits:
    cpu: "32"
  template:
    metadata:
      labels:
        workload-tier: priority-demo
    spec:
      nodeClassRef:
        group: eks.amazonaws.com
        kind: NodeClass
        name: demo-default
      taints:
        - key: workload-tier
          value: priority-demo
          effect: NoSchedule
      requirements:
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["on-demand"]
        - key: kubernetes.io/arch
          operator: In
          values: ["amd64"]
        - key: eks.amazonaws.com/instance-category
          operator: In
          values: ["c", "m"]
---
# Ten 1-vCPU pods: more than graviton-first's 8 vCPU limit can hold.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: priority-demo
  namespace: demo-nodepools
  labels:
    app: priority-demo
spec:
  replicas: 10
  selector:
    matchLabels:
      app: priority-demo
  template:
    metadata:
      labels:
        app: priority-demo
    spec:
      nodeSelector:
        workload-tier: priority-demo
      tolerations:
        - key: workload-tier
          operator: Equal
          value: priority-demo
          effect: NoSchedule
      containers:
        - name: worker
          image: public.ecr.aws/docker/library/busybox:1.36   # multi-arch
          command: ["sh", "-c", "echo \"on $(uname -m)\"; sleep 3600"]
          resources:
            requests:
              cpu: "1"
              memory: 256Mi
            limits:
              memory: 256Mi

graviton-first (weight 100, Graviton, max 8 vCPU) is tried before x86-spill (weight 10, x86). Ten 1-vCPU pods need more than 8 vCPU of nodes, so some must spill over. Both pools are tainted so nothing else in the cluster is drawn to the weight-100 pool: weight sets priority, taints and selectors set exclusivity.

kubectl apply -f labs/nodepools-weighted.yaml
kubectl get nodeclaims -w

Ctrl+C once the new NodeClaims are ready, then:

kubectl get nodes -l workload-tier=priority-demo -L karpenter.sh/nodepool,kubernetes.io/arch,node.kubernetes.io/instance-type
kubectl -n demo-nodepools logs -l app=priority-demo --prefix --tail=1

From the test run:

NAME                  ...   NODEPOOL         ARCH    INSTANCE-TYPE
i-0123456789abc0009   ...   graviton-first   arm64   c6g.2xlarge
i-0123456789abc0010   ...   x86-spill        amd64   c6a.xlarge

   7 aarch64
   3 x86_64

One 8-vCPU Graviton node used up graviton-first's whole 8 vCPU limit and took seven pods; the other three fell through to x86-spill. Swap the arm64 requirement for karpenter.sh/capacity-type: reserved (with a NodeClass that has capacityReservationSelectorTerms) and this becomes "use what you prepaid first, then on-demand".

Undo:

kubectl delete -f labs/nodepools-weighted.yaml

Deleting the NodePools drains and terminates their nodes.

Lab 3: Balanced vs WhenEmptyOrUnderutilized

You don't need to apply anything. Compare our Spot pool with the same pool written the pre-1.37 way:

diff manifests/21-nodepool-spot-burst.yaml labs/nodepool-spot-burst-legacy.yaml
labs/nodepool-spot-burst-legacy.yaml in full
# Lab: for the side-by-side diff only. You don't need to apply it.
# Identical to spot-burst except the disruption block, which is the pre-1.37
# default behaviour: bin-pack aggressively, regardless of what the move costs.
# Walkthrough: docs/09-optional-labs.md
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: spot-burst-legacy
  labels:
    talk: mastering-custom-node-pools
spec:
  limits:
    cpu: "64"
  disruption:
    consolidationPolicy: WhenEmptyOrUnderutilized
    consolidateAfter: 30s
    budgets:
      - nodes: "30%"
  template:
    metadata:
      labels:
        workload-tier: burst-legacy
    spec:
      nodeClassRef:
        group: eks.amazonaws.com
        kind: NodeClass
        name: demo-default
      expireAfter: 168h
      terminationGracePeriod: 30m
      taints:
        - key: workload-tier
          value: burst-legacy
          effect: NoSchedule
      requirements:
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["spot"]
        - 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"]

Apart from names, labels and comments, the difference is the disruption block:

spot-burst spot-burst-legacy
consolidationPolicy Balanced WhenEmptyOrUnderutilized
consolidateAfter 1m 30s

WhenEmptyOrUnderutilized takes any move that saves money, however little, and evicts pods to do it. Balanced scores each move, savings against disruption, and skips the marginal ones. AWS's guidance: if you're on WhenEmpty, Balanced gets you consolidation savings; if you're on WhenEmptyOrUnderutilized, Balanced stops you paying disruption for marginal gains. Existing pools keep their policy until you change it.

Undo: nothing to undo.

Lab 4: live drift

This replaces real nodes

Changing the NodeClass drifts every node in both pools: the two static nodes and any Spot nodes. On a production cluster this is the blast radius the talk warns about. Here it's the point.

Don't run it while report-batch is still running: when the test run did, drift evicted the batch pods mid-sleep and the job failed. Bare pods (like the tuning probes) are evicted and not recreated.

Change one kubelet setting, log rotation file count from 5 to 6:

kubectl patch nodeclass demo-default --type=merge \
  -p '{"spec":{"advancedCompute":{"kubelet":{"logging":{"containerLogMaxFiles":6}}}}}'

Watch the NodeClaims' Drifted condition:

kubectl get nodeclaims -o custom-columns='NAME:.metadata.name,POOL:.metadata.labels.karpenter\.sh/nodepool,DRIFTED:.status.conditions[?(@.type=="Drifted")].status'

What happens next depends on the pool's budgets and on the clock:

  • spot-burst: its 30% budget allows drift, so drifted nodes are replaced.
  • stable-static: the always-on budget allows one node at a time, unless it's inside the business-hours window (09:00–17:00 NZDT, Mon–Fri, as written), where drift is blocked. Check what UTC time it is: date -u.

When replacement runs, you'll see a new NodeClaim launch, checkout-api pods move one at a time (the PDB), and the old node go. kubectl get nodeclaims -w shows it live. In test runs (outside the window) both static nodes were replaced, one after the other, in 2½–4 minutes, and checkout-api never had fewer than 3 of its 4 replicas available: the PDB's maxUnavailable: 1 at work. The events tell the story:

eks-auto-mode/compute   DisruptionTerminating      stable-static-np8tv   Disrupting NodeClaim: Drifted
eks-auto-mode/compute   DisruptionLaunching        stable-static-xkk85   Launching NodeClaim: Drifted
eks-auto-mode/compute   DisruptionWaitingReadiness stable-static-xkk85   Waiting on readiness to continue disruption
eks-auto-mode/compute   DisruptionTerminating      stable-static-c4p59   Disrupting NodeClaim: Drifted

Undo: patch the value back. Note this drifts the nodes again:

kubectl patch nodeclass demo-default --type=merge \
  -p '{"spec":{"advancedCompute":{"kubelet":{"logging":{"containerLogMaxFiles":5}}}}}'

Lab 5: scale the static pool

Static capacity is set, not demanded. Ask for a third node:

kubectl scale nodepool stable-static --replicas=3
kubectl get nodeclaims -w

A new stable-static node appears (Ready in under 20 seconds in the test run) with no pending pod having asked for it. Scaling bypasses node disruption budgets but still respects PDBs.

Undo: back to two. That matters here, because limits.nodes is 3: at three replicas there's no headroom for a drift replacement.

kubectl scale nodepool stable-static --replicas=2

(kubectl patch nodepool stable-static --type=merge -p '{"spec":{"replicas":2}}' does the same thing.)

Next: 10 Cleanup.