Questão de Kubernetes Fundamentals #019e3a4f
What is the primary mechanism to identify grouped objects in a Kubernetes cluster?
Custom Resources
Labels
Label Selector
Pod
Explicação Oficial / Explicações da Comunidade
In Kubernetes, the primary mechanism to identify and group objects is through Labels. Labels are key-value pairs attached to Kubernetes objects (such as Pods, Services, Deployments) that are used to organize and select subsets of objects. They are not unique identifiers; multiple objects can share the same label. The Label Selector is the mechanism that uses labels to filter and identify a group of objects, but the question asks for the mechanism to identify grouped objects, which is the label itself. Labels are the fundamental building blocks for grouping, while label selectors are the query mechanism.
How it Works:
- Labels are defined in the
metadata.labelsfield of a Kubernetes object manifest. For example, a Pod might have labelsapp: frontendandtier: web. - To select a group of objects, you use a label selector in API calls,
kubectlcommands, or within resource definitions (e.g., a Service'sselectorfield). The selector matches objects that have all the specified labels. - Labels enable flexible grouping without hardcoding object names, allowing dynamic association and management.
Why the correct value is right:
- Labels are the direct answer because they are the attribute attached to objects that defines their grouping. Without labels, there is no way to logically group objects. The Kubernetes documentation states: "Labels are intended to be used to specify identifying attributes of objects that are meaningful and relevant to users."
Why the incorrect values are wrong:
- Custom Resources are extensions of the Kubernetes API that allow you to store and retrieve structured data. They do not inherently group objects; they are a way to define new resource types.
- Label Selector is the query mechanism that uses labels to identify a group, but it is not the primary mechanism for identifying grouped objects; it is the tool that leverages labels. The question asks for the mechanism itself, which is the label.
- Pod is a fundamental workload object that runs containers. It is not a grouping mechanism; it is one of the objects that can be grouped using labels.