Interview Prep/Kubernetes/Resources, autoscaling and scheduling

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 →

  1. Use nodeAffinity to target node labels such as instance type
  2. Use podAffinity with topologyKey: kubernetes.io/hostname to co-locate app and cache
  3. Use podAntiAffinity to spread replicas
  4. Prefer preferredDuringSchedulingIgnoredDuringExecution for soft rules
  5. 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.

All Kubernetes questions Roadmap: Kubernetes core

More on Resources, autoscaling and scheduling