kuberneteskube-scheduler

How to change default kube-scheduler in kubernetes


This doc tells about how to run multiple scheduler. But I m not able to understand how does default scheduler is decided? Is it based on --leader-elect option?

Can I tell Kubernetes to use my-custom-scheduler as default scheduler instead of kube-scheduler? Is there another way to specify scheduler other than schedulerName in Pod/Deployment spec.


Solution

  • How does default scheduler is decided? Is it based on --leader-elect option?

    No it's not based on --leader-elect which is to run multiple replicated copy of the same scheduler with leader election enabled so that only one replica acts as leader at any given point in time.

    Can I tell Kubernetes to use my-custom-scheduler as default scheduler instead of kube-scheduler?

    You don't need to change the default scheduler at the kubernetes cluster level because you can tell kubernetes to use your custom scheduler in the pod spec. An example below using my-scheduler instead of default-scheduler

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-with-custom-scheduler
    spec:
      schedulerName: my-scheduler
      containers:
      - name: pod-with-custom-scheduler
        image: k8s.gcr.io/pause:2.0
    

    Above pod will be scheduled by my-scheduler instead of default kube-scheduler. If you omit the schedulerName then it will be scheduled by default kube-scheduler

    From the doc

    By default, one profile with the scheduler name default-scheduler is created. This profile includes the default plugins described above. When declaring more than one profile, a unique scheduler name for each of them is required.

    If a Pod doesn't specify a scheduler name, kube-apiserver will set it to default-scheduler. Therefore, a profile with this scheduler name should exist to get those pods scheduled

    So you could just replace the existing kube scheduler with your scheduler with name default-scheduler.

    1. Replace the docker image of kube-scheduler with your image in /etc/kubernetes/manifests/kube-scheduler.yaml or
    2. Edit the kube scheduler deployment and change the image