KUBERNETES · KCNA · CHAPTER 3

Scheduling

How Kubernetes decides which node each pod runs on, and how you can steer that decision.

12 min readKCNA domain: Kubernetes Fundamentals (44%)Level: beginner

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:

  1. Filter: discards the nodes where the pod doesn't fit or isn't allowed (resources, taints, selectors).
  2. Score: ranks the remaining nodes, for example by how many free resources they have.
  3. Bind: writes the winning node's name into nodeName. From then on, that node's kubelet starts the pod.
How kube-scheduler places a pod A new pod without nodeName waits in the scheduling queue. The scheduler filters out the nodes that can't run it, scores the rest, picks the best one and binds the pod to it by setting nodeName. new podnodeName: — 1 · FILTER enough CPU and memory? taints tolerated? nodeSelector / affinity? node03 ✗ discarded 2 · SCORE node01 · 72 node02 · 91 most free resources wins 3 · BIND nodeName: node02 kubelet starts it If no node passes the filter, the pod stays Pending.

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
Troubleshooting hint. A pod stuck in 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.

Taints and tolerations Node01 has the taint app=blue:NoSchedule. Pods A and B have no toleration, so they can only go to node02 or node03. Pod C tolerates the taint, so it may land on node01, but it can also go to the other nodes. NODE01 · TAINT app=blue NODE02 NODE03 pod C pod A pod B only pods that tolerate effect: NoSchedule Taint (node) repels · toleration (pod) allows A toleration doesn't send pod C to node01: it only lets it go there. To pin a pod to a node, combine it with nodeSelector or node affinity.

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:

EffectNew pods without a tolerationPods already running on the node
NoScheduleAren't scheduled on the nodeKeep running
PreferNoScheduleThe node is avoided if possibleKeep running
NoExecuteAren't scheduled on the nodeAre 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"
Watch out. A toleration doesn't send the pod to that node: it only allows it to go there. To pin a pod to a specific node you combine it with 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 stays Pending.
  • 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 and node affinity Three nodes are labeled size=large, size=medium and size=small. A nodeSelector size=large matches only the large node. A node affinity with operator In and values large and medium matches two nodes. NODE01 · size=large NODE02 · size=medium NODE03 · size=small 16 CPU · 64 GiB 8 CPU · 32 GiB 2 CPU · 4 GiB nodeSelector: size=large affinity · size In [large, medium] small: excluded by both

nodeSelector requires an exact match; node affinity supports lists and exclusions. Diagram: The House of Routing.

The winning combination. Taints and tolerations keep other pods off your nodes; node affinity keeps your pods from going to other nodes. To dedicate nodes to an application, you use both together.

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.

Requests and limits The request is what the scheduler reserves on the node. The limit is the ceiling. A container that goes over its CPU limit is throttled; one that goes over its memory limit is killed with OOMKilled. CPU request 250m limit 500m over the limit → throttled MEMORY request 256Mi limit 512Mi over the limit → OOMKilled The scheduler places pods by their requests, not by what they actually use. CPU can be squeezed; memory can't, so the kernel kills the container.

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"
Common practice. Always declare 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 staticPodPath in 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 kubeadm starts the control plane: kube-apiserver, etcd, kube-scheduler and kube-controller-manager are static pods on the control plane node.
Static podDaemonSet
Who creates itThe kubelet, from a local directoryThe DaemonSet controller, through the API server
Where it runsOnly on that nodeOn every node (or the selected ones)
Typical useControl plane componentsMonitoring, 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, Exists and 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

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.

Navigate