|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * nodes/scheduling/nodes-custom-scheduler.adoc |
| 4 | + |
| 5 | +[id="nodes-custom-scheduler-deploying-pods_{context}"] |
| 6 | += Deploying pods using a custom scheduler |
| 7 | + |
| 8 | +After the custom scheduler is deployed in your cluster, you can configure pods to use that scheduler instead of the default scheduler. |
| 9 | + |
| 10 | +[NOTE] |
| 11 | +==== |
| 12 | +Each scheduler has a separate view of resources in a cluster. For that reason, each scheduler should operate over its own set of nodes. |
| 13 | +
|
| 14 | +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. |
| 15 | +==== |
| 16 | + |
| 17 | +.Prerequisites |
| 18 | + |
| 19 | +* You have access to the cluster as a user with the `cluster-admin` role. |
| 20 | +* The custom scheduler has been deployed in the cluster. |
| 21 | + |
| 22 | +.Procedure |
| 23 | + |
| 24 | +. If your cluster uses role-based access control (RBAC), add the custom scheduler name to the `system:kube-scheduler` cluster role. |
| 25 | + |
| 26 | +.. Edit the `system:kube-scheduler` cluster role: |
| 27 | ++ |
| 28 | +[source,terminal] |
| 29 | +---- |
| 30 | +$ oc edit clusterrole system:kube-scheduler |
| 31 | +---- |
| 32 | + |
| 33 | +.. Add the name of the custom scheduler to the `resourceNames` lists for the `leases` and `endpoints` resources: |
| 34 | ++ |
| 35 | +[source,yaml] |
| 36 | +---- |
| 37 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 38 | +kind: ClusterRole |
| 39 | +metadata: |
| 40 | + annotations: |
| 41 | + rbac.authorization.kubernetes.io/autoupdate: "true" |
| 42 | + creationTimestamp: "2021-07-07T10:19:14Z" |
| 43 | + labels: |
| 44 | + kubernetes.io/bootstrapping: rbac-defaults |
| 45 | + name: system:kube-scheduler |
| 46 | + resourceVersion: "125" |
| 47 | + uid: 53896c70-b332-420a-b2a4-f72c822313f2 |
| 48 | +rules: |
| 49 | +... |
| 50 | +- apiGroups: |
| 51 | + - coordination.k8s.io |
| 52 | + resources: |
| 53 | + - leases |
| 54 | + verbs: |
| 55 | + - create |
| 56 | +- apiGroups: |
| 57 | + - coordination.k8s.io |
| 58 | + resourceNames: |
| 59 | + - kube-scheduler |
| 60 | + - custom-scheduler <1> |
| 61 | + resources: |
| 62 | + - leases |
| 63 | + verbs: |
| 64 | + - get |
| 65 | + - update |
| 66 | +- apiGroups: |
| 67 | + - "" |
| 68 | + resources: |
| 69 | + - endpoints |
| 70 | + verbs: |
| 71 | + - create |
| 72 | +- apiGroups: |
| 73 | + - "" |
| 74 | + resourceNames: |
| 75 | + - kube-scheduler |
| 76 | + - custom-scheduler <1> |
| 77 | + resources: |
| 78 | + - endpoints |
| 79 | + verbs: |
| 80 | + - get |
| 81 | + - update |
| 82 | +... |
| 83 | +---- |
| 84 | +<1> This example uses `custom-scheduler` as the custom scheduler name. |
| 85 | + |
| 86 | +. Create a `Pod` configuration and specify the name of the custom scheduler in the `schedulerName` parameter: |
| 87 | ++ |
| 88 | +.Example `custom-scheduler-example.yaml` file |
| 89 | +[source,yaml] |
| 90 | +---- |
| 91 | +apiVersion: v1 |
| 92 | +kind: Pod |
| 93 | +metadata: |
| 94 | + name: custom-scheduler-example |
| 95 | + labels: |
| 96 | + name: custom-scheduler-example |
| 97 | +spec: |
| 98 | + schedulerName: custom-scheduler <1> |
| 99 | + containers: |
| 100 | + - name: pod-with-second-annotation-container |
| 101 | + image: docker.io/ocpqe/hello-pod |
| 102 | +---- |
| 103 | +<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. |
| 104 | + |
| 105 | +. Create the pod: |
| 106 | ++ |
| 107 | +[source,terminal] |
| 108 | +---- |
| 109 | +$ oc create -f custom-scheduler-example.yaml |
| 110 | +---- |
| 111 | + |
| 112 | +.Verification |
| 113 | + |
| 114 | +. Enter the following command to check that the pod was created: |
| 115 | ++ |
| 116 | +[source,terminal] |
| 117 | +---- |
| 118 | +$ oc get pod custom-scheduler-example |
| 119 | +---- |
| 120 | ++ |
| 121 | +The `custom-scheduler-example` pod is listed in the output: |
| 122 | ++ |
| 123 | +[source,terminal] |
| 124 | +---- |
| 125 | +NAME READY STATUS RESTARTS AGE |
| 126 | +custom-scheduler-example 1/1 Running 0 4m |
| 127 | +---- |
| 128 | + |
| 129 | +. Enter the following command to check that the custom scheduler has scheduled the pod: |
| 130 | ++ |
| 131 | +[source,terminal] |
| 132 | +---- |
| 133 | +$ oc describe pod custom-scheduler-example |
| 134 | +---- |
| 135 | ++ |
| 136 | +The scheduler, `custom-scheduler`, is listed as shown in the following truncated output: |
| 137 | ++ |
| 138 | +[source,terminal] |
| 139 | +---- |
| 140 | +Events: |
| 141 | + Type Reason Age From Message |
| 142 | + ---- ------ ---- ---- ------- |
| 143 | + Normal Scheduled <unknown> custom-scheduler Successfully assigned default/custom-scheduler-example to <node_name> |
| 144 | +---- |
0 commit comments