Bird
0
0

You wrote this pod spec with pod anti-affinity but pods are still scheduled on the same node. What is the likely error?

medium📝 Troubleshoot Q14 of 15
Kubernetes - Scheduling
You wrote this pod spec with pod anti-affinity but pods are still scheduled on the same node. What is the likely error?
affinity:
  podAntiAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
    - weight: 100
      podAffinityTerm:
        labelSelector:
          matchLabels:
            app: myapp
        topologyKey: "kubernetes.io/hostname"
AIncorrect labelSelector syntax causes failure
BMissing nodeSelector in the pod spec
CUsing preferred instead of required anti-affinity allows scheduling on same node
DtopologyKey should be set to "zone" instead of hostname
Step-by-Step Solution
Solution:
  1. Step 1: Understand pod anti-affinity types

    Preferred anti-affinity suggests avoiding co-location but does not enforce it strictly. Required anti-affinity enforces pods not to be scheduled together.
  2. Step 2: Analyze the pod spec anti-affinity type

    The spec uses preferredDuringSchedulingIgnoredDuringExecution, which is a soft rule. This allows pods to be scheduled on the same node if needed.
  3. Final Answer:

    Using preferred instead of required anti-affinity allows scheduling on same node -> Option C
  4. Quick Check:

    Preferred anti-affinity is a soft rule [OK]
Quick Trick: Preferred anti-affinity is soft; use required to enforce [OK]
Common Mistakes:
  • Confusing preferred and required anti-affinity
  • Assuming labelSelector syntax is wrong without checking
  • Thinking topologyKey must be zone for anti-affinity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes