DCA · Question #165
Two pods bear the same label, app: dev. Will a label selector matching app: dev match both of these pods?
The correct answer is D. Yes, if the pods are in the same Kubernetes namespace as the object bearing the label selector. Yes, a label selector matching app: dev will match both pods if they possess this label and are located within the same Kubernetes namespace as the object using the selector.
Question
Two pods bear the same label, app: dev. Will a label selector matching app: dev match both of these pods?
Options
- AYes, as long as all the containers in those pods are passing their livenessProbes and
- BYes, if both pods were pre-existing when the label selector was declared.
- CYes, if the pods are in the same Kubernetes namespace as the object bearing the label selector
- DYes, if the pods are in the same Kubernetes namespace as the object bearing the label selector
How the community answered
(24 responses)- B4% (1)
- C4% (1)
- D92% (22)
Why each option
Yes, a label selector matching `app: dev` will match both pods if they possess this label and are located within the same Kubernetes namespace as the object using the selector.
Pod health (livenessProbes/readinessProbes) does not affect whether a label selector matches a pod; it only affects whether the pod is considered ready or available for traffic.
The existence of pods before a label selector is declared does not impact matching; label selectors dynamically evaluate current labels at any given time.
This statement is identical to choice D, which is the correct answer and accurately describes the conditions for label selector matching.
Kubernetes label selectors dynamically match resources based solely on their assigned labels, irrespective of their health or creation time. Importantly, label selectors are namespace-scoped, meaning an object (like a Service or Deployment) with a selector will only find matching pods within its own Kubernetes namespace.
Concept tested: Kubernetes label selectors and namespace scope
Source: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
Topics
Community Discussion
No community discussion yet for this question.