Kubernetes cluster have a default scheduler kube-scheduler. If the default scheduler does not suits our requirement we can also create our own scheduler. In the post we will discus how to create multiple scheduler and schedule pods based on different scheduler.
I am using the Virtualbox(running in Ubuntu 18.04 physical machine) for this entire setup . The physical machine is Dell inspiron laptop with 12GB RAM , Intel® Core™ i7-6500U CPU @ 2.50GHz × 4 and 512GB SSD hardisk.
Step 1: Copy the default scheduler yaml and modify
Copy the default scheduler yaml from master node and modify the name.
In this below example i am naming the custom schedule are my-scheduler. Add a ServiceAccount and ClusterRoleBinding to the yaml file as given below.
The key changes made are
line 27: name: my-scheduler
line 30: serviceAccountName: my-scheduler
line 38: - –leader-elect=false
line 39: - –scheduler-name=my-scheduler
Step 2: Create the custom scheduler
Now we can see a new custom scheduler my-scheduler is running along with defautl scheduler kube-scheduler-kubernetes1
Step 3: Edit the custerrole for kube-scheduler
If RBAC is enabled on your cluster, you must update the system:kube-scheduler cluster role. Edit the clusterrole for kube-scheduler and modify.
Below are the key changes made in orignal file
line 33: - my-scheduler
line 131: - storageclasses
Step 4: Create pods with different types of scheduler
Create a pod without explicitly mentioning any scheuler name. This pod should be scheduled by default scheduler kube-scheduler
Create a pod by explicitly mentioning custom scheuler name my-scheduler.
Now we can see both the pods are created and running
From the events, we can see pod nginx-pod-custom-scheduler is scheduled by my-scheduler and nginx-pod-default-scheduler by default-scheduler.