Bird
0
0

Which of the following is the correct syntax to specify a required node affinity in a pod spec?

easy📝 Configuration Q12 of 15
Kubernetes - Scheduling
Which of the following is the correct syntax to specify a required node affinity in a pod spec?
A"nodeAffinity": {"preferredDuringSchedulingIgnoredDuringExecution": [{"weight": 1, "preference": {"matchExpressions": [{"key": "disktype", "operator": "In", "values": ["ssd"]}]}}]}
B"podAffinity": {"requiredDuringSchedulingIgnoredDuringExecution": {"labelSelector": {"matchLabels": {"disktype": "ssd"}}}}
C"nodeSelector": {"disktype": "ssd"}
D"nodeAffinity": {"requiredDuringSchedulingIgnoredDuringExecution": {"nodeSelectorTerms": [{"matchExpressions": [{"key": "disktype", "operator": "In", "values": ["ssd"]}]}]}}
Step-by-Step Solution
Solution:
  1. Step 1: Identify required node affinity syntax

    Required node affinity uses the key requiredDuringSchedulingIgnoredDuringExecution with nodeSelectorTerms and matchExpressions to specify node labels.
  2. Step 2: Check options for correct structure

    "nodeAffinity": {"requiredDuringSchedulingIgnoredDuringExecution": {"nodeSelectorTerms": [{"matchExpressions": [{"key": "disktype", "operator": "In", "values": ["ssd"]}]}]}} matches the required node affinity syntax. "nodeAffinity": {"preferredDuringSchedulingIgnoredDuringExecution": [{"weight": 1, "preference": {"matchExpressions": [{"key": "disktype", "operator": "In", "values": ["ssd"]}]}}]} is preferred affinity, C is nodeSelector (different syntax), and D is pod affinity, not node affinity.
  3. Final Answer:

    "nodeAffinity": {"requiredDuringSchedulingIgnoredDuringExecution": {"nodeSelectorTerms": [{"matchExpressions": [{"key": "disktype", "operator": "In", "values": ["ssd"]}]}]}} -> Option D
  4. Quick Check:

    Required node affinity uses requiredDuringSchedulingIgnoredDuringExecution [OK]
Quick Trick: Required node affinity uses requiredDuringSchedulingIgnoredDuringExecution [OK]
Common Mistakes:
  • Confusing preferred and required affinity syntax
  • Using podAffinity instead of nodeAffinity
  • Mixing nodeSelector with nodeAffinity syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes