From point A to point B
Point A: you can create pods, Deployments and Services, but Kubernetes decides for you where each one runs. Point B: by the end of this chapter you'll understand how the scheduler picks a node and you'll be able to steer it: reserve nodes, attract pods to certain nodes, reserve CPU and memory, and run an agent on every node.
Scheduling is a core part of the Kubernetes Fundamentals domain (44% of the KCNA exam) and one of the first things you check when a pod is stuck in Pending.
How the scheduler picks a node
Every pod has a nodeName field that is empty when it's created. kube-scheduler watches for pods that don't have a node yet and, for each one, does three things:
- Filter: discards the nodes where the pod doesn't fit or isn't allowed (resources, taints, selectors).
- Score: ranks the remaining nodes, for example by how many free resources they have.
- Bind: writes the winning node's name into
nodeName. From then on, that node's kubelet starts the pod.
Filter, score and bind: that's how kube-scheduler decides. Diagram: The House of Routing.
Manual assignment
If there's no scheduler, or you want to decide yourself, you can set nodeName in the YAML when you create the pod. The scheduler no longer gets involved.
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
nodeName: node02
containers:
- name: nginx
image: nginx:1.27-alpine
The field can only be set when the pod is created; Kubernetes won't let you change it afterwards. To assign an existing pod, you send a Binding object to the API server, which is exactly what the scheduler does under the hood:
apiVersion: v1
kind: Binding
metadata:
name: web
target:
apiVersion: v1
kind: Node
name: node02
Pending almost always means the scheduler found no valid node. kubectl describe pod tells you why in the Events section.Labels, selectors and annotations
Almost all scheduling builds on these three ideas:
- Labels: key-value pairs that group objects:
app: web,env: prod,size: large. - Selectors: the way to filter those groups. ReplicaSets and Services use them, and so do you from
kubectl. - Annotations: informational metadata that isn't used for selection: build version, owner, a link to the docs.
kubectl get pods --selector app=web
kubectl get pods -l app=web,tier=front-end
kubectl get pods --show-labels
kubectl label pod web env=prod
kubectl get all -l env=prod
In a ReplicaSet or a Deployment, what counts for finding pods are the labels in selector.matchLabels, which must match the pod template. The labels in the Deployment's own metadata are there so that other objects can find it.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
labels:
app: web
annotations:
buildversion: "1.34"
owner: "team-platform@example.com"
Taints and tolerations
A taint goes on a node and repels pods. A toleration goes on a pod and lets it ignore that taint. It's how you reserve nodes: for example, GPU nodes only for the workloads that need them.
The taint repels; the toleration allows, but doesn't force. Diagram: The House of Routing.
Step 1: the taint on the node
kubectl taint nodes node01 app=blue:NoSchedule
kubectl describe node node01 | grep Taints
kubectl taint nodes node01 app=blue:NoSchedule-
The format is key=value:effect, and the trailing dash on the last line removes the taint. There are three effects:
| Effect | New pods without a toleration | Pods already running on the node |
|---|---|---|
NoSchedule | Aren't scheduled on the node | Keep running |
PreferNoSchedule | The node is avoided if possible | Keep running |
NoExecute | Aren't scheduled on the node | Are evicted if they don't tolerate it |
Step 2: the toleration on the pod
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
containers:
- name: nginx
image: nginx:1.27-alpine
tolerations:
- key: "app"
operator: "Equal"
value: "blue"
effect: "NoSchedule"
nodeSelector or node affinity, covered next. It's also why control plane nodes don't get your pods: kubeadm gives them the taint node-role.kubernetes.io/control-plane:NoSchedule.nodeSelector and node affinity
Now the opposite case: you want to attract a pod to certain nodes, for example a heavy job to the biggest nodes. First you label the node, then you ask for it in the pod.
nodeSelector: the simple way
kubectl label nodes node01 size=large
kubectl get nodes --show-labels
apiVersion: v1
kind: Pod
metadata:
name: data-processor
spec:
nodeSelector:
size: large
containers:
- name: processor
image: busybox:1.36
command: ["sleep", "3600"]
nodeSelector only supports equality. You can't say "large or medium" or "anything that's not small". That's what affinity is for.
Node affinity: expressive rules
apiVersion: v1
kind: Pod
metadata:
name: data-processor
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: size
operator: In
values: ["large", "medium"]
containers:
- name: processor
image: busybox:1.36
command: ["sleep", "3600"]
The operators are In, NotIn, Exists, DoesNotExist, Gt and Lt. The long names describe when the rule applies:
requiredDuringSchedulingIgnoredDuringExecution: mandatory when the pod is scheduled; if no node matches, the pod staysPending.preferredDuringSchedulingIgnoredDuringExecution: a preference; if it can't be met, the pod goes to another node.
In both cases, IgnoredDuringExecution means that if you change the node's labels later, pods that are already running don't move.
nodeSelector requires an exact match; node affinity supports lists and exclusions. Diagram: The House of Routing.
Requests, limits and LimitRange
Every pod consumes CPU and memory from the node it runs on. For each container you can declare two values:
- requests: what the scheduler reserves on the node. A pod only goes to a node with that much capacity free.
- limits: the ceiling the container must not exceed.
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
containers:
- name: nginx
image: nginx:1.27-alpine
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "500m"
memory: "512Mi"
CPU is measured in cores: 1 is one vCPU and 250m is a quarter. Memory is measured in bytes with suffixes like Mi or Gi.
Going over the CPU limit slows the container down; going over the memory limit kills it. Diagram: The House of Routing.
- If a container wants more CPU than its limit, it's throttled: it runs slower, but it stays alive.
- If it uses more memory than its limit, the kernel kills it with the status
OOMKilled.
Kubernetes sets no requests or limits by default. A LimitRange sets default values for the containers in a namespace that don't declare them. Remember that the ResourceQuota from chapter 2 caps the namespace total; a LimitRange works container by container.
apiVersion: v1
kind: LimitRange
metadata:
name: defaults
namespace: dev
spec:
limits:
- type: Container
defaultRequest:
cpu: "250m"
memory: "256Mi"
default:
cpu: "500m"
memory: "512Mi"
requests: without them, the scheduler places pods blindly. For CPU, many teams set requests and no limits, so a pod can use spare CPU without taking it from others. For memory, a limit is a good idea.DaemonSets: one pod on every node
A DaemonSet makes sure there's one copy of a pod on every node (or on the nodes you choose). If you add a node, it creates the pod there; if you remove the node, the pod goes with it. It's ideal for monitoring agents, log collectors and networking pieces such as kube-proxy or a CNI.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: log-agent
spec:
selector:
matchLabels:
app: log-agent
template:
metadata:
labels:
app: log-agent
spec:
containers:
- name: agent
image: fluent/fluent-bit:3.1
kubectl apply -f daemonset.yaml
kubectl get daemonsets -A
kubectl describe daemonset log-agent
The YAML is almost a ReplicaSet's, but without replicas: the number of pods is set by the number of nodes. Since Kubernetes 1.12, DaemonSet pods are placed by the regular scheduler, using node affinity rules that the DaemonSet sets itself.
Static pods
The kubelet doesn't need the API server to start pods. It watches a directory on the node, usually /etc/kubernetes/manifests, and creates a pod for every definition file it finds. If you delete the file, it deletes the pod. These are static pods.
grep staticPodPath /var/lib/kubelet/config.yaml
ls /etc/kubernetes/manifests
crictl ps
kubectl get pods -n kube-system
- The path is set by
staticPodPathin the kubelet configuration. - If the node belongs to a cluster, the API server shows a read-only copy of the pod (a mirror pod), with the node name as a suffix. You can't edit it with
kubectl: you change the file. - That's how
kubeadmstarts the control plane: kube-apiserver, etcd, kube-scheduler and kube-controller-manager are static pods on the control plane node.
| Static pod | DaemonSet | |
|---|---|---|
| Who creates it | The kubelet, from a local directory | The DaemonSet controller, through the API server |
| Where it runs | Only on that node | On every node (or the selected ones) |
| Typical use | Control plane components | Monitoring, logging and networking agents |
Custom schedulers and profiles
Kubernetes is extensible here too: you can deploy additional schedulers with their own logic, each with a different name. A pod picks who schedules it with schedulerName; if it doesn't say, default-scheduler does it.
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
schedulerName: my-scheduler
containers:
- name: nginx
image: nginx:1.27-alpine
kubectl get events -o wide
kubectl logs my-scheduler -n kube-system
The events show which scheduler assigned each pod. Often you don't need another binary: with the profiles in KubeSchedulerConfiguration, a single kube-scheduler offers several behaviors. Each profile turns plugins on or off at the extension points of the scheduling cycle, such as queueSort, filter, score and bind.
KCNA-style challenge
Answer before you open the solution. Getting it wrong here is the cheapest way to learn.
1. A pod has a toleration for node01's taint. Is it guaranteed to run on node01?
No. The toleration only allows it on node01; the scheduler can put it on any other node. To pin it you need nodeSelector or node affinity.
2. Which taint effect evicts pods that are already running on the node and don't tolerate it?
NoExecute. NoSchedule and PreferNoSchedule only affect new pods.
3. A container goes over its memory limit. What happens?
It's killed with OOMKilled. If it goes over the CPU limit, it's only throttled.
4. You need a log agent on every node, including nodes added later. Which object do you use?
A DaemonSet. It creates a pod on every node and keeps it that way as the cluster grows or shrinks.
5. Who creates static pods?
The kubelet, from the files in the staticPodPath directory, without going through the scheduler.
Key takeaways
- kube-scheduler filters, scores and binds: it writes the chosen node into
nodeName. - Labels group, selectors filter and annotations only inform.
- The taint (on the node) repels; the toleration (on the pod) allows, but doesn't force.
- nodeSelector asks for equality; node affinity supports
In,NotIn,Existsand more. - Requests is what gets reserved; limits is the ceiling. Going over the CPU limit throttles; going over the memory limit kills the container.
- A DaemonSet puts one pod on every node; a static pod is created by the kubelet from a local directory.
- A pod picks its scheduler with
schedulerName; profiles customize the default scheduler.
In the next chapter you'll get into orchestration security: authentication, authorization with RBAC and service accounts.
Official resources
- Kubernetes Schedulerkubernetes.io
- Assigning Pods to Nodeskubernetes.io
- Labels and Selectorskubernetes.io
- Taints and Tolerationskubernetes.io
- Resource Management for Pods and Containerskubernetes.io
- Limit Rangeskubernetes.io
- DaemonSetkubernetes.io
- Create static Podskubernetes.io
- Configure Multiple Schedulerskubernetes.io
- Scheduler Configurationkubernetes.io
- Kubernetes and Cloud Native Associate (KCNA)cncf.io
Source and credits. Chapter written from Jesús Espinoza's study notes on KodeKloud's KCNA course (January to April 2026). Text drafted with AI assistance; original diagrams by The House of Routing. Technical details and YAML examples were checked against the official Kubernetes and CNCF documentation.