Bird
0
0

You applied this podAntiAffinity rule but pods are still scheduled on the same node:

medium📝 Troubleshoot Q6 of 15
Kubernetes - Scheduling
You applied this podAntiAffinity rule but pods are still scheduled on the same node:
podAntiAffinity:
  requiredDuringSchedulingIgnoredDuringExecution:
  - labelSelector:
      matchLabels:
        app: frontend
    topologyKey: invalid-key

What is the most probable cause?
AThe rule is preferred, not required, so pods can still schedule on the same node.
BThe <code>labelSelector</code> is incorrect because it should use <code>matchExpressions</code> instead of <code>matchLabels</code>.
CThe <code>topologyKey</code> value <code>invalid-key</code> does not match any valid node label, so the rule is ignored.
DThe podAntiAffinity rule must be defined under <code>podAffinity</code> to work correctly.
Step-by-Step Solution
Solution:
  1. Step 1: Check the topologyKey

    The topologyKey must correspond to a valid node label such as kubernetes.io/hostname or failure-domain.beta.kubernetes.io/zone.
  2. Step 2: Understand scheduler behavior

    If the topologyKey is invalid, the scheduler cannot enforce the anti-affinity rule, effectively ignoring it.
  3. Step 3: Verify other fields

    The labelSelector syntax is valid and the rule is required, so those are not the issue.
  4. Final Answer:

    The topologyKey value invalid-key does not match any valid node label, so the rule is ignored. correctly identifies the cause.
  5. Quick Check:

    Invalid topologyKey disables anti-affinity enforcement [OK]
Quick Trick: Ensure topologyKey matches a valid node label [OK]
Common Mistakes:
  • Using an invalid or misspelled topologyKey
  • Confusing required and preferred rules
  • Misplacing podAntiAffinity under podAffinity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes