LAB04a: Taint & Toleration

Understanding in One Line

  • Taint = node says “don’t place pods here unless they tolerate this.”

  • Toleration = pod says “I accept your taint, I can be scheduled.”

Taints & Tolerations

Make control-plane schedulable

Apply taints on nodes

Test pod scheduling behavior

Verify when pods are blocked or allowed

This is exactly how senior DevOps/SREs demonstrate the concept.

LAB OVERVIEW

  1. Check cluster nodes

  2. Remove control-plane taint → make CP schedulable

  3. Create a taint on a worker node

  4. Deploy a pod WITHOUT toleration → should fail to schedule

  5. Deploy a pod WITH toleration → should successfully schedule

  6. Understand taint effects (NoSchedule, PreferNoSchedule, NoExecute)

  7. Optional: Add taints BACK to control-plane node

PRE-REQUISITE

A kubeadm or k3s or minikube cluster.

STEP 1: Check Nodes

Typical output:

STEP 2: Make Control Plane Schedulable

Kubeadm clusters have this taint:

Remove it:

Verify:

If nothing shows → control plane is now schedulable.

STEP 3: Add a Taint to a Node

Let's taint worker1:

Verify:

You should see:

Meaning:

  • Pods without toleration → ❌ cannot be scheduled on worker1

  • Pods with matching toleration → ✔ allowed


STEP 4: Deploy a Pod WITHOUT Toleration

Create file:

pod-no-toleration.yaml

Apply:

Check pod:

Expected:

  • Pod will NOT schedule onto worker1 (tainted)

  • It will only schedule onto cp-node or worker2

Check events:

You should see message like:

STEP 5: Deploy a Pod WITH Toleration

Create file:

pod-with-toleration.yaml

Apply:

Check:

Expected:

  • Pod will schedule on worker1

  • Because it has matching toleration.

Check:

LAB UNDERSTANDING: WHY THIS WORKS

Taint applied:

Meaning:

  • Kubernetes will not schedule pods on worker1 unless they tolerate the taint.

Toleration used:

This tells scheduler:

  • “I can live on tainted nodes”

STEP 6: Add Taints Back to Control Plane (Optional)

Re-taint CP:

Or for older labels:

Check:

SUMMARY OF LAB RESULTS

Node
Taint
Pod Behavior

cp-node

No taint

Any pod can run

worker1

environment=dev:NoSchedule

Only pods WITH toleration can run

worker2

No taint

Any pod can run

Yes you can do the entire taint & toleration lab using ONLY kubectl commands (no YAML). This is how SREs quickly test taints in real clusters.

Below is the command-only lab.

LAB: Taints & Tolerations Using Only Commands

1. Make control-plane schedulable

Remove default taint:

Or older clusters:

2. Add taint to a worker node

Example: taint worker1

3. Create a pod WITHOUT toleration (command-only)

Check where it got scheduled:

Describe event:

It should show:

4. Create a pod WITH toleration (command-only)

Using kubectl run --overrides

Check where scheduled:

It should schedule on worker1.

Shortcut: Create pod with toleration using oneliners

If you want fast testing, this is easier:

Option A: kubectl run with --dry-run pipe to apply

Option B: use kubectl-krew plugin (if installed)

5. Remove a taint from worker

6. Add taint back to control-plane (optional)

Last updated