0
0
Kubernetesdevops~10 mins

Node selectors for simple scheduling in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Node selectors for simple scheduling
Pod Spec Created
Add nodeSelector Field
Pod Submitted to API Server
Scheduler Checks Nodes
Match Node Labels with nodeSelector?
NoWait or Fail
Yes
Pod Assigned to Matching Node
Pod Runs on Selected Node
The pod spec includes a nodeSelector field. The scheduler matches this with node labels to assign the pod to a suitable node.
Execution Sample
Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  nodeSelector:
    disktype: ssd
  containers:
  - name: app
    image: nginx
This pod requests scheduling only on nodes labeled with disktype=ssd.
Process Table
StepActionScheduler CheckResultPod State
1Pod spec created with nodeSelector disktype=ssdN/APod ready for schedulingPending
2Pod submitted to API serverN/APod acceptedPending
3Scheduler scans nodesCheck node labelsFound nodes with disktype=ssdPending
4Scheduler matches nodeSelector with node labelsMatch disktype=ssd?Match found on node-1Pending
5Scheduler assigns pod to node-1Assignment donePod bound to node-1Running
6Pod starts running on node-1N/APod runningRunning
💡 Pod assigned to node with matching label disktype=ssd and starts running.
Status Tracker
VariableStartAfter Step 3After Step 5Final
Pod StateNot createdPendingRunningRunning
Node SelectedNoneNonenode-1node-1
Key Moments - 3 Insights
Why does the pod stay in Pending state before scheduling?
The pod is Pending because the scheduler has not yet assigned it to a node. See execution_table step 2 and 3 where the pod is accepted but not assigned.
What happens if no node matches the nodeSelector labels?
The pod remains Pending and will not be scheduled until a matching node appears. This is shown by the scheduler check in step 4 where no match would cause waiting.
Can the pod run on a node without the matching label?
No, the scheduler enforces nodeSelector strictly. The pod only runs on nodes matching the labels, as shown in step 5 and 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does the scheduler assign the pod to a node?
AStep 4
BStep 3
CStep 5
DStep 6
💡 Hint
Check the 'Result' column for the assignment action in the execution_table.
According to the variable tracker, what is the pod state after step 3?
APending
BRunning
CSucceeded
DFailed
💡 Hint
Look at the 'Pod State' row and the 'After Step 3' column in variable_tracker.
If the nodeSelector label was changed to disktype=hdd, what would happen in the execution table?
AScheduler finds matching nodes and assigns pod immediately
BPod remains Pending if no node has disktype=hdd label
CPod runs on any node regardless of label
DPod is deleted automatically
💡 Hint
Refer to key_moments about what happens if no node matches the nodeSelector.
Concept Snapshot
Node selectors let you tell Kubernetes to run pods only on nodes with specific labels.
Add a nodeSelector field in pod spec with key-value pairs.
Scheduler matches these labels to node labels.
Pod stays Pending if no matching node is found.
Simple way to control pod placement without complex rules.
Full Transcript
Node selectors are a simple way to schedule pods on specific nodes in Kubernetes. You add a nodeSelector field to the pod specification with key-value pairs that must match node labels. When the pod is submitted, the scheduler looks for nodes with matching labels. If it finds one, it assigns the pod to that node and the pod starts running. If no matching node exists, the pod stays in Pending state until a suitable node appears. This method helps control where pods run using simple label matching.