Explain node affinity, pod affinity and anti-affinity with a real use.
IntermediateScenarioResources, autoscaling and scheduling
Answer
Situation read → A cache should sit close to its app, while replicas must not share a node.
What I'd do →
- Use
nodeAffinityto target node labels such as instance type - Use
podAffinitywithtopologyKey: kubernetes.io/hostnameto co-locate app and cache - Use
podAntiAffinityto spread replicas - Prefer
preferredDuringSchedulingIgnoredDuringExecutionfor soft rules - Verify with
kubectl get pods -o wide
Why → Required rules can block scheduling, preferred rules only bias it.
Interview tip → Note the cost of anti-affinity at large scale.
More on Resources, autoscaling and scheduling
How do you choose requests and limits for a new service?BeginnerPods are Pending with `0/6 nodes are available: 6 Insufficient cpu`. What do you do?IntermediateExplain QoS classes and which pods get evicted first.IntermediateCPU limits cause latency spikes though average usage is low. Why and what is the fix?IntermediateHow do you configure an HPA on CPU?BeginnerHPA shows `<unknown>/70%` for CPU. What do you do?Intermediate