Skip to main content
KubernetesMediumSingle Choice

Kubernetes Question

Statement

What does the "nodeSelector" within a PodSpec use to place Pods on the target nodes?

#kubernetes#scheduling#nodeselector
A

Annotations

B

IP Addresses

C

Hostnames

D

Labels

Correct

Resolution & Explanations

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 nodeSelector is a map of label keys to values. For example: nodeSelector: { disktype: ssd }.
  • The scheduler matches the Pod's nodeSelector against 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 via nodeName field, but that bypasses scheduling.
  • Hostnames: Hostnames are not used by nodeSelector. While a node's hostname is often a label (kubernetes.io/hostname), the nodeSelector matches arbitrary labels, not specifically hostnames.