Understanding the Default Scheduler Behavior
Every pod definition includes a field callednodeName, 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:
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 thenodeName field in the manifest. For example, to schedule the pod on a node called “node02”, update your manifest as follows:
The
nodeName must be set during pod creation. Once the pod is running, Kubernetes does not permit modifications to the nodeName field.Reassigning a Running Pod Using a Binding Object
If a pod is already running and you need to change its node assignment, you cannot modify itsnodeName directly. In this scenario, you can create a binding object that mimics the scheduler’s behavior.
-
Create a binding object that specifies the target node (“node02”):
-
The original pod definition remains unchanged:
-
Convert the YAML binding to JSON (e.g., save it as
binding.json) and send a POST request to the pod’s binding API using curl:
Quick Reference Table
| Method | Use Case | Example Snippet Reference |
|---|---|---|
| Direct Assignment | Set nodeName during pod creation | See manifest with nodeName: node02 |
| Using a Binding Object | Reassign a running pod | See binding object example |