Manual Scheduling
Usage of Manual Scheduling
There are different ways to manual schedule a pod on a node. Now for some cases, you don't want to rely on the Kubernetes built-in scheduler or you don't have a scheduler in your cluster, or you want to schedule the pod by yourself. How would you do that?
So we know that the scheduling works like this
- What to schedule? -> Pod
- Which node to schedule?
- Schedule/Bind Pod to Node
Here is an example of Pod definition YAML file.
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
spec:
containers:
- name: ubuntu
image: ubuntu
nodeName: node01
Every pod has a field called nodeName
and by default is not set. Normally you won't set this field, as this field will auto being added by Kubernetes. Here are the steps of how Kubernetes will auto add this field.
- First, the Scheduler will go through all the pods and **check which pods do not **have this property set:
nodeName
. - The Scheduler will run the scheduling algorithm to determine and identify the right node for the pod.
- Lastly, the scheduler will schedule the pod on the node by setting this property set:
nodeName
to the name of the node by creating a binding object.
If you don't have a scheduler in your cluster, then when you deployed the pods, those pods status will be in Pending state, as nobody monitor and schedule nodes for those deployed pods.
In this case, you can manually assign those pods to the specified node by yourself without a scheduler (set the nodeName
field to the node name). Note that, you can only specify the nodeName
at the Pod creation time.
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
spec:
containers:
- name: ubuntu
image: ubuntu
nodeName: node01
Here is the another scenario, assume your pod already created and you would like to assign the deployed pod to a node. Now, we know that once you deployed the Pod, Kubernetes don't allow you to modify the nodeName
property field. How would you do that?
Well, in this case, we can create a Binding object and send a POST request to the Pod's binding API, with this method, we can assign a node to the existing deployed pod.
apiVersion: v1
kind: Binding
metadata:
name: sample-binding
target:
apiVersion: v1
kind: Node
name: node03
Remember, you must convert the above YAML file to JSON format for POST request.
Reference (opens in a new tab)
curl -H "Content-Type: application/json" \
-X POST \
-d '{"apiVersion": "v1","kind": "Binding","metadata": {"name": "sample-binding"},"target": {"apiVersion": "v1","kind": "Node","name": "node03"}}' \
http://{server-url}/api/v1/namespaces/{namespace}/pods/{pod-name}/binding