Kubernetes
medium
Questão de Kubernetes #019e3a4f
Enunciado da Questão
Kubernetes
#kubernetes
#scheduling
#nodeselector
Médio
What does the "nodeSelector" within a PodSpec use to place Pods on the target nodes?
A
Annotations
B
IP Addresses
C
Hostnames
D
Labels
Correta
Explicação Oficial / Explicações da Comunidade
The nodeSelector field in a PodSpec is used to constrain which nodes a Pod can be scheduled on, based on the node's labels. Labels are key-value pairs attached to Kubernetes objects, such as nodes, to identify attributes. When a Pod specifies a nodeSelector, the scheduler only considers nodes that have all the specified labels. This is a simple and static scheduling constraint.
How it Works
- Nodes are labeled during creation or via
kubectl label nodes <node-name> <label-key>=<label-value>. - A Pod's
nodeSelectoris a map of label keys to values. For example:nodeSelector: { disktype: ssd }. - The scheduler matches the Pod's
nodeSelectoragainst node labels; only nodes with matching labels are eligible.
Why Labels are Correct
Labels are the mechanism used by nodeSelector to select nodes. They are designed for identifying and grouping resources.
Why Other Options are Incorrect
- Annotations: Annotations are non-identifying metadata used for tooling or external systems, not for scheduling decisions.
- IP Addresses: IP addresses are not used by
nodeSelector. Node selection by IP is possible vianodeNamefield, but that bypasses scheduling. - Hostnames: Hostnames are not used by
nodeSelector. While a node's hostname is often a label (kubernetes.io/hostname), thenodeSelectormatches arbitrary labels, not specifically hostnames.