The Kubernetes Scheduler is not permitted to update a pod’s .spec.nodeName. Therefore, instead of updating the Pod, the Kubernetes Scheduler creates a Kubernetes Binding Object. On creation of a Binding Object the Kubernetes API will update the Pod’s .spec.nodeName.
The scheduler code has a clean separation that watches new pods as they get created and identifies the most suitable node to host them. It then creates bindings (pod to node bindings) for the pods using the master API.
What if the pod is already created and you want to assign pod to a node?
Kubernetes wont’ allow you to modify the nodeName property of a pod. So another way to assign existing pod to node is to manually create a binding object and sent a post request to the pods binding API. This is what the actual scheduler does:
apiVersion: v1
kind: Binding
metadata:
name: nginx
target:
apiVersion: v1
kind: Node
name: node02
In the binding object we specify the target node with a name of the node. Then send a post request to the pods binding API by setting data property in the JSON format. Here you must convert your YAML to its equivalent JSON format:
curl --header "Content-Type: application/json" --request POST --data \
'{ \
"apiVersion": "v1", \
"kind": "Binding", \
"metadata": { \
"name": "nginx" \
}, \
"target": { \
"apiVersion": "v1", \
"kind": "Node", \
"name": "node02" \
} \
}' http://$SERVER/api/v1/namespaces/dafault/pods/$PODNAME/binding