Version note: examples use the Kubernetes v1.35 documentation snapshot, not necessarily the newest release. Check current support and component compatibility. These commands were not tested on a live cluster.
What this guide covers
The Kubernetes scheduler selects a node that meets a Pod’s requirements. Resource requests, node labels and taints can prevent placement even when another machine appears idle.
Before you start
Use a test cluster with a node named worker1, or replace that name with your worker’s actual name. Do not change production node labels for this exercise.
Step 1: Label the worker
Run:
kubectl label node worker1 workload-tier=lab --overwrite
kubectl get nodes -L workload-tier
kubectl create namespace scheduling-lab
The label is used by the example Deployment to select an eligible node.
Step 2: Create a workload with requirements
Save this as placement.yaml and apply it with kubectl apply -f placement.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: report-api
namespace: scheduling-lab
spec:
replicas: 2
selector:
matchLabels:
app: report-api
template:
metadata:
labels:
app: report-api
spec:
nodeSelector:
workload-tier: lab
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: report-api
containers:
- name: api
image: nginx:1.28.0
resources:
requests:
cpu: 250m
memory: 128Mi
limits:
cpu: 500m
memory: 256Mi
nodeSelector requires matching labels. Resource requests reserve scheduling capacity; limits constrain runtime use. A node’s current CPU usage is not the same as its unallocated requested capacity.
Step 3: Read scheduling events
If a Pod stays Pending, replace the placeholder and run:
kubectl -n scheduling-lab get pods -o wide
kubectl -n scheduling-lab describe pod CHOSEN_PENDING_POD
kubectl describe node worker1
kubectl -n scheduling-lab get events --sort-by=.metadata.creationTimestamp
Events may report insufficient resources, an unmatched selector or a taint. Correct the actual mismatch. Do not remove the control-plane taint just to fit another test Pod.
Check the result
Check kubectl get pods -o wide in the namespace to see the chosen node. Reduce this lab’s workload or add capacity if requests cannot fit; lowering requests without measurement can overload the worker.
Conversation
0 commentsNo comments yet. Start the conversation below.