Custom Scheduling

Overview

You can run multiple, custom schedulers alongside the default scheduler and configure which scheduler to use for each pods.

To schedule a given pod using a specific scheduler, specify the name of the scheduler in that pod specification.

Information on how to create the scheduler binary is outside the scope of this document. For an example, see Configure Multiple Schedulers in the Kubernetes documentation.

Package the Scheduler

The general process for including a custom scheduler in your cluster involves creating an image and including that image in a deployment.

  1. Package your scheduler binary into a container image.

  2. Create a container image containing the scheduler binary.

    For example:

    1. FROM <source-image>
    2. ADD <path-to-binary> /usr/local/bin/kube-scheduler
  3. Save the file as Dockerfile, build the image, and push it to a registry.

    For example:

    1. docker build -t <dest_env_registry_ip>:<port>/<namespace>/<image name>:<tag>
    2. docker push <dest_env_registry_ip>:<port>/<namespace>/<image name>:<tag>
  4. In OKD, create a deployment for the custom scheduler.

    1. apiVersion: v1
    2. kind: ServiceAccount
    3. metadata:
    4. name: custom-scheduler
    5. namespace: kube-system
    6. ---
    7. apiVersion: rbac.authorization.k8s.io/v1
    8. kind: ClusterRoleBinding
    9. metadata:
    10. name: custom-scheduler
    11. subjects:
    12. - kind: ServiceAccount
    13. name: custom-scheduler
    14. namespace: kube-system
    15. roleRef:
    16. kind: ClusterRole
    17. name: system:kube-scheduler
    18. apiGroup: rbac.authorization.k8s.io
    19. ---
    20. apiVersion: apps/v1
    21. kind: Deployment
    22. metadata:
    23. name: custom-scheduler
    24. namespace: kube-system
    25. labels:
    26. app: custom-scheduler
    27. spec:
    28. replicas: 1
    29. selector:
    30. matchLabels:
    31. app: custom-scheduler
    32. template:
    33. metadata:
    34. labels:
    35. app: custom-scheduler
    36. spec:
    37. serviceAccount: custom-scheduler
    38. containers:
    39. - name: custom-scheduler
    40. image: "<namespace>/<image name>:<tag>" (1)
    41. imagePullPolicy: Always
    1Specify the container image you created for the custom scheduler.

Deploying Pods using a Custom Scheduler

After your custom scheduler is deployed in your cluster, you can configure pods to use that scheduler instead of the default scheduler.

  1. Create or edit a pod configuration and specify the name of the scheduler with the schedulerName parameter. The name must be unique.

    Sample pod specification with scheduler

    1. apiVersion: v1
    2. kind: Pod
    3. metadata:
    4. name: custom-scheduler-example
    5. labels:
    6. name: custom-scheduler-example
    7. spec:
    8. schedulerName: custom-scheduler (1)
    9. containers:
    10. - name: pod-with-second-annotation-container
    11. image: docker.io/ocpqe/hello-pod
    1The name of the scheduler to use. When no scheduler name is supplied, the pod is automatically scheduled using the default scheduler.
  2. Run the following command to create the pod:

    1. $ oc create -f <file-name>.yaml

    For example:

    1. $ oc create -f custom-scheduler-example.yaml
  3. Run the following command to check that the pod was created:

    1. $ oc get pod <file-name>

    For example:

    1. $ oc get pod custom-scheduler-example
    2. NAME READY STATUS RESTARTS AGE
    3. custom-scheduler-example 1/1 Running 0 4m
  4. Run the following command to check that the custom scheduler scheduled the pod:

    1. $ oc describe pod <pod-name>

    For example:

    1. $ oc describe pod custom-scheduler-example

    The name of the scheduler is listed, as shown in the following truncated output:

    1. ...
    2. Events:
    3. FirstSeen LastSeen Count From SubObjectPath Type Reason Message
    4. --------- -------- ----- ---- ------------- -------- ------ -------
    5. 1m 1m 1 custom-scheduler Normal Scheduled Successfully assigned custom-scheduler to <$node1>
    6. ...