- As new pod definition files are created, Kubernetes goes through them and looks for the property nodeName
- If this property does not exist, then Kubernetes has the job of scheduling this pod
- It then looks for the nodes that can host this pod and schedules it there
- And the pod definition is updated with the nodeName where it is running
- The property nodeName in the below definition file is optional.
- If the property is specified then kubernetes automatically schedules the pod on the selected node. This is called manual scheduling.
- Once the Kubernetes identifies the node on which to run, it creates a binding object that binds the pod with the node on which the pod will run
pod-definition.yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
location: IN
spec:
nodeName: node01
containers:
- name: nginx-container
image: nginx
- name: backed-db
image: redis
Manual Scheduling
- If the scheduler is not running or there is no scheduler in kubernetes, then pods will remain in Pending state
- To run the pods, the definition file has to be updated to add the node on which the pod can run
- Remember that Kubernetes does not allow a nodeName to be specified once the pod is created
- So for manual scheduling, nodeName has to be added to the yaml file before creating the pod
- So if the pod is already created with no scheduler, then a bind object has to be created
- This has to be converted to a JSON format and sent to Kubernetes as a POST API request, mimicking what Kubernetes actually does.
pod-binding-definition.yaml
apiVersion: v1
kind: Binding
metadata:
name: myapp-pod
target:
apiVersion: v1
kind: Node
name: node01
-----------------
{
"apiVersion": "v1",
"kind": "Binding",
"metadata": {
"name": "nginx"
},
"target": {
"apiVersion": "v1",
"kind": "Node",
"name": "node01"
}
}
----------------------
curl --header "Content-Type:application/json" --request POST --data '{ "apiVersion": "v1", "kind": "Binding", "metadata": { "name": "nginx" }, "target": { "apiVersion": "v1", "kind": "Node", "name": "node01" }}' http://$SERVER/api/v1/namespaces/default/pods/$PODNAME/binding/
How to know if scheduler is running ?
Check the pods running in the kube-system namespace
Here there is no scheduler running, so Pods will not be scheduled in this kubernetes
Comments
Post a Comment