How can you combine node affinity and pod anti-affinity to ensure pods run on nodes labeled ssd=true but never on the same node as pods labeled app=db?
hard📝 Workflow Q9 of 15
Kubernetes - Scheduling
How can you combine node affinity and pod anti-affinity to ensure pods run on nodes labeled ssd=true but never on the same node as pods labeled app=db?
AUse preferredDuringSchedulingIgnoredDuringExecution nodeAffinity for ssd=true and preferredDuringSchedulingIgnoredDuringExecution podAffinity for app=db
BUse requiredDuringSchedulingIgnoredDuringExecution nodeAffinity for ssd=true and requiredDuringSchedulingIgnoredDuringExecution podAntiAffinity for app=db with hostname topologyKey
CUse requiredDuringSchedulingIgnoredDuringExecution podAffinity for ssd=true and requiredDuringSchedulingIgnoredDuringExecution nodeAntiAffinity for app=db
DUse preferredDuringSchedulingIgnoredDuringExecution podAntiAffinity for ssd=true and requiredDuringSchedulingIgnoredDuringExecution nodeAffinity for app=db
Step-by-Step Solution
Solution:
Step 1: Set node affinity for nodes with ssd=true
Use requiredDuringSchedulingIgnoredDuringExecution nodeAffinity to ensure pods only run on nodes labeled ssd=true.
Step 2: Set pod anti-affinity to avoid co-locating with app=db pods
Use requiredDuringSchedulingIgnoredDuringExecution podAntiAffinity with label app=db and topologyKey kubernetes.io/hostname to prevent same node placement.
Final Answer:
Use requiredDuringSchedulingIgnoredDuringExecution nodeAffinity for ssd=true and requiredDuringSchedulingIgnoredDuringExecution podAntiAffinity for app=db with hostname topologyKey -> Option B
Quick Check:
Combine required nodeAffinity + podAntiAffinity for strict placement [OK]
Quick Trick:Combine required nodeAffinity and podAntiAffinity for strict rules [OK]
Common Mistakes:
Mixing podAffinity with nodeAffinity incorrectly
Using preferred instead of required for strict rules
Confusing nodeAntiAffinity with podAntiAffinity
Master "Scheduling" in Kubernetes
9 interactive learning modes - each teaches the same concept differently