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
- nvmeTaints 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.
Comments
Comments
Post a Comment