Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
K8s Scheduling Kubernetes Kubernetes: From Zero to Production Module 6 - Scheduling and Scaling

Scheduling - nodeSelector, Affinity, and Taints

Reviewed & accurate
AI Summary

What You Will Learn

Intermediate

  • How the scheduler assigns Pods to nodes
  • nodeSelector and node affinity
  • Taints and tolerations
Terminalyaml
# nodeSelector - simplest form
spec:
  nodeSelector:
    disktype: ssd    # Only schedule on nodes with this label

# Node affinity - more expressive
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: disktype
            operator: In
            values:
            - ssd
            - nvme

Taints and Tolerations

Terminalbash
# Taint a node (repel Pods)
kubectl taint nodes node1 dedicated=gpu:NoSchedule

# Toleration (allow Pod on tainted node)
spec:
  tolerations:
  - key: "dedicated"
    operator: "Equal"
    value: "gpu"
    effect: "NoSchedule"

Practical Exercise

Label a node: kubectl label node minikube disktype=ssd
Create a Pod with nodeSelector: disktype: ssd
Apply and verify Pod runs on that node
Try a Pod with nodeSelector: disktype: hdd (should fail)

Key Takeaways

  • nodeSelector: simple label matching.
  • Node affinity: expressive (In, NotIn, Exists).
  • Taints repel Pods. Tolerations allow them.
  • Taint effect: NoSchedule, PreferNoSchedule, NoExecute.
  • Use for: GPU nodes, specialized hardware, dedicated nodes.
Previously: Module 5 covered storage.
Today: You learned: Control where Pods run in the cluster.
Next: Lesson 32 covers resources.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments