Running a custom scheduler
To schedule a given pod using a specific scheduler, specify the name of the scheduler in that specification.
To include a custom scheduler in your cluster, include the image for a custom scheduler in a deployment.
Prerequisites
You have access to the cluster as a user with the
cluster-admin
role.You have a scheduler binary.
Information on how to create a scheduler binary is outside the scope of this document. For an example, see in the Kubernetes documentation. Note that the actual functionality of your custom scheduler is not supported by Red Hat.
You have created an image containing the scheduler binary and pushed it to a registry.
Procedure
-
Example
custom-scheduler.yaml
file Create the deployment resources in the cluster:
$ oc create -f custom-scheduler.yaml
Verification
Verify that the scheduler pod is running:
$ oc get pods -n kube-system
The custom scheduler pod is listed as
Running
:NAME READY STATUS RESTARTS AGE
custom-scheduler-6cd7c4b8bc-854zb 1/1 Running 0 2m
After the custom scheduler is deployed in your cluster, you can configure pods to use that scheduler instead of the default scheduler.
Each scheduler has a separate view of resources in a cluster. For that reason, each scheduler should operate over its own set of nodes. If two or more schedulers operate on the same node, they might intervene with each other and schedule more pods on the same node than there are available resources for. Pods might get rejected due to insufficient resources in this case. |
Prerequisites
You have access to the cluster as a user with the
cluster-admin
role.
Procedure
If your cluster uses role-based access control (RBAC), add the custom scheduler name to the
system:kube-scheduler
cluster role.Edit the
system:kube-scheduler
cluster role:Add the name of the custom scheduler to the
resourceNames
lists for theleases
andendpoints
resources:apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
creationTimestamp: "2021-07-07T10:19:14Z"
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: system:kube-scheduler
resourceVersion: "125"
rules:
...
- coordination.k8s.io
resources:
- leases
verbs:
- create
- apiGroups:
- coordination.k8s.io
resourceNames:
- kube-scheduler
- custom-scheduler (1)
resources:
- leases
verbs:
- get
- update
- apiGroups:
- ""
resources:
- endpoints
verbs:
- create
- apiGroups:
- ""
resourceNames:
- kube-scheduler
resources:
- endpoints
- get
- update
...
Create a
Pod
configuration and specify the name of the custom scheduler in theschedulerName
parameter:Example
custom-scheduler-example.yaml
fileapiVersion: v1
kind: Pod
metadata:
name: custom-scheduler-example
labels:
name: custom-scheduler-example
spec:
schedulerName: custom-scheduler (1)
containers:
- name: pod-with-second-annotation-container
image: docker.io/ocpqe/hello-pod
1 The name of the custom scheduler to use, which is custom-scheduler
in this example. When no scheduler name is supplied, the pod is automatically scheduled using the default scheduler.Create the pod:
$ oc create -f custom-scheduler-example.yaml
Verification
Enter the following command to check that the pod was created:
The
custom-scheduler-example
pod is listed in the output:NAME READY STATUS RESTARTS AGE
custom-scheduler-example 1/1 Running 0 4m
-
$ oc describe pod custom-scheduler-example
The scheduler,
custom-scheduler
, is listed as shown in the following truncated output:Events:
Type Reason Age From Message
---- ------ ---- ---- -------