Even though you do not need an explicit configuration file for the default scheduler, creating one can help you document and customize the scheduling behavior if needed.
Default Scheduler Configuration
A configuration file for the default scheduler might look like this:Creating a Custom Scheduler
To create a custom scheduler, prepare a separate configuration file that specifies a unique scheduler name. For example:Deploying an Additional Scheduler as a Service
When deploying an extra scheduler as a service, you typically use the same kube-scheduler binary or a modified version with a unique configuration file. Below are two examples—one for the default scheduler and another for a custom scheduler.Default Scheduler Service
Custom Scheduler Service
Create a service file for your custom scheduler, for example,my-scheduler-2.service:
Deploying a Scheduler as a Pod
Another common approach is deploying the scheduler as a pod. In this setup, define a pod manifest that points to the custom kube-scheduler configuration file. Below is an example of a basic pod definition:Leader Election for High Availability
When running multiple instances of the same scheduler (such as on different master nodes), enable leader election to ensure only one instance is active at a time. The following pod manifest and configuration file enable leader election: Pod manifest with leader election enabled:Deploying a Scheduler as a Deployment
In many Kubernetes environments, control plane components are deployed as pods or Deployments using kubeadm. You can also deploy your custom scheduler in this manner by building a custom Docker image.Building a Custom Scheduler Image
Clone the Kubernetes repository and build your scheduler:RBAC Setup for the Custom Scheduler
For secure deployment, create a ServiceAccount and bind the necessary ClusterRoles. Here’s an example configuration:Deployment Manifest Example
Below is a sample Deployment manifest for your custom scheduler. This deployment uses a ConfigMap to mount the custom configuration file as a volume:Using the Custom Scheduler for Pods
Once your custom scheduler is deployed, you can instruct specific pods to use it by setting the schedulerName field in their manifests. For example, here is a pod manifest for an nginx pod using the custom scheduler:| LAST SEEN | COUNT | NAME | KIND | TYPE | REASON | SOURCE | MESSAGE |
|---|---|---|---|---|---|---|---|
| 9s | 1 | nginx.15 | Pod | Normal | Scheduled | my-custom-scheduler | Successfully assigned default/nginx to node01 |
| 8s | 1 | nginx.15 | Pod | Normal | Pulling | kubelet, node01 | pulling image “nginx” |
| 2s | 1 | nginx.15 | Pod | Normal | Pulled | kubelet, node01 | Successfully pulled image “nginx” |
| 2s | 1 | nginx.15 | Pod | Normal | Created | kubelet, node01 | Created container |
| 2s | 1 | nginx.15 | Pod | Normal | Started | kubelet, node01 | Started container |
To troubleshoot your custom scheduler, view its logs with:kubectl logs my-custom-scheduler —namespace=kube-systemReviewing these logs will help pinpoint configuration errors or leader election issues.