Skip to content

Manual Scheduling

This guide explains how to assign pods to nodes without relying on Kubernetes’ built-in scheduler for tighter control over pod placement.

Welcome to this lesson on manually scheduling pods in Kubernetes. This guide explains how to assign pods to nodes without relying on Kubernetes’ built-in scheduler. Manual scheduling can be useful in niche scenarios where you need tighter control over pod placement. In this article, we review a basic pod manifest, demonstrate how manual scheduling works, and show you how to use binding objects to reassign pods if necessary.

Understanding the Default Scheduler Behavior

Every pod definition includes a field called nodeName, which is left unset by default. The Kubernetes scheduler automatically scans for pods without a nodeName and selects an appropriate node by updating this field and creating a binding object. Consider the basic pod manifest below:

pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: podinfo
  labels:
    name: podinfo
spec:
  containers:
  - name: podinfo
    image: ghcr.io/stefanprodan/podinfo:latest
    ports:
    - containerPort: 9898

Typically, you do not include the nodeName field in your manifest. The scheduler uses this field only after selecting a node for the pod.

Manually Setting the Node Name

To manually assign a pod to a specific node during creation, populate the nodeName field in the manifest. For example, to schedule the pod on a node called "node02", update your manifest as follows:

pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: podinfo
  labels:
    name: podinfo
spec:
  nodeName: kind-worker2
  containers:
  - name: podinfo
    image: ghcr.io/stefanprodan/podinfo:latest
    ports:
    - containerPort: 9898

After creating the pod with this manifest, check its status with:

kubectl get pods -A --field-selector spec.nodeName=kind-worker2 -l name=podinfo
NAMESPACE   NAME      READY   STATUS    RESTARTS   AGE
default     podinfo   1/1     Running   0          4m59s

Info

The nodeName must be set during pod creation. Once the pod is running, Kubernetes does not permit modifications to the nodeName field.

Additional Resources