Interview Kubernetes, Docker, Helm & Podman

What are node selectors, node affinity, and anti-affinity?

Kubernetes, Docker, Helm & Podman · Intermediate level

Answer

nodeSelector is a simple label match. Node affinity is more expressive and supports required or preferred rules, while Pod affinity and anti-affinity place Pods near or away from other Pods based on labels and topology.

Technical explanation

Required affinity is a hard constraint; preferred affinity influences scoring but can be ignored if necessary.

Anti-affinity can protect availability but may block scheduling if topology domains or labels are too strict.

Scheduling controls place workloads correctly; RBAC and ServiceAccounts decide what identities can do after placement.

Use labels consistently because Services, Deployments, affinities, policies, and topology spread all depend on label selection.

Every constraint should be testable with events: FailedScheduling, denied API calls, or observed placement.

Hands-on example

1. Create a lab namespace for this exercise with explicit labels, ServiceAccounts, roles, node labels, or taints: place Pods using nodeSelector, node affinity, and pod anti-affinity.

2. Use kubectl auth can-i, kubectl describe pod, and scheduling events to verify the expected decision.

3. Test a negative case, such as missing permission, missing toleration, or impossible affinity, and capture the exact error.

4. Convert the validated YAML into a reusable platform pattern with clear naming and labels.

Preparing for an interview?

Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.

More Kubernetes, Docker, Helm & Podman interview questions

← All Kubernetes, Docker, Helm & Podman questions