Scheduling Pods
Schedulers
What to schedule? Every pod has a field called nodeName that is not set by default when you create the manifest file. This is automatically set by Kubernetes.
apiVersion: v1
kind: Pod
metadata:
name: myapp
labels:
name: myapp
spec:
containers:
- name: myapp
image: <Image>
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: <Port>
nodeName: node01 # No need to add this field.
Which node to schedule? The scheduler then goes through all the pods and looks for Pods that doesn't have this property.
Schedule the pod
Once Kubernetes identifies the candidate pods, it schedule the pod on the node by setting the nodeName property to the name of the node. This is called binding the object.
Manual Scheduling
If there is no scheduler, you can manually assign a Pod to a node by setting the nodeName property in the manifest. This can only be done during Pod creation and cannot be changed afterward. To move an existing Pod to a different node, you must create a Binding object.
Binding Object Example:
# binding.yml
apiVersion: v1
kind: Binding
metadata:
name: myapp
target:
apiVersion: v1
kind: Node
name: node01 # Name of the node to schedule the Pod on
Convert the YAML to JSON for the POST request:
{
"apiVersion": "v1",
"kind": "Binding",
"metadata": {
"name": "myapp"
},
"target": {
"apiVersion": "v1",
"kind": "Node",
"name": "node01"
}
}
Finally, send a POST request to the Pod binding API:
curl --request POST \
-H "Content-Type:application/json" \
-d @path/to/binding.json \
http://$SERVER/api/v1/namespaces/default/pods/$PODNAME/binding