This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.3.10. カスタムスケジューラーの実行
デフォルトのスケジューラーと共に複数のカスタムスケジューラーを実行し、各 Pod に使用するスケジューラーを設定できます。
これは OpenShift Container Platform でカスタムスケジューラーを使用することはサポートされていますが、Red Hat ではカスタムスケジューラーの機能を直接サポートしません。
デフォルトのスケジューラーを設定する方法については、Configuring the default scheduler to control pod placement を参照してください。
特定のスケジューラーを使用して指定された Pod をスケジュールするには、Pod
の仕様にスケジューラーの名前を指定 します。
3.10.1. カスタムスケジューラーのデプロイ
クラスターにカスタムスケジューラーを追加するには、デプロイメントにカスタムスケジューラーのイメージを追加します。
前提条件
-
cluster-admin
ロールを持つユーザーとしてクラスターにアクセスできる。 スケジューラーバイナリーがある。
注記スケジューラーバイナリーの作成方法に関する情報は、本書では扱っておりません。たとえば、Kubernetes ドキュメントの Configure Multiple Schedulers を参照してください。カスタムスケジューラーの実際の機能は、Red Hat ではサポートされない点に留意してください。
- スケジューラーバイナリーを含むイメージを作成し、これをレジストリーにプッシュしている。
手順
カスタムスケジューラーのデプロイメントリソースを含むファイルを作成します。
custom-scheduler.yaml
ファイルの例apiVersion: v1 kind: ServiceAccount metadata: name: custom-scheduler namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: custom-scheduler-as-kube-scheduler subjects: - kind: ServiceAccount name: custom-scheduler namespace: kube-system roleRef: kind: ClusterRole name: system:kube-scheduler apiGroup: rbac.authorization.k8s.io --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: custom-scheduler-as-volume-scheduler subjects: - kind: ServiceAccount name: custom-scheduler namespace: kube-system roleRef: kind: ClusterRole name: system:volume-scheduler apiGroup: rbac.authorization.k8s.io --- apiVersion: apps/v1 kind: Deployment metadata: labels: component: scheduler tier: control-plane name: custom-scheduler namespace: kube-system spec: selector: matchLabels: component: scheduler tier: control-plane replicas: 1 template: metadata: labels: component: scheduler tier: control-plane version: second spec: serviceAccountName: custom-scheduler containers: - command: - /usr/local/bin/kube-scheduler - --address=0.0.0.0 - --leader-elect=false - --scheduler-name=custom-scheduler image: "<namespace>/<image_name>:<tag>" livenessProbe: httpGet: path: /healthz port: 10251 initialDelaySeconds: 15 name: kube-second-scheduler readinessProbe: httpGet: path: /healthz port: 10251 resources: requests: cpu: '0.1' securityContext: privileged: false volumeMounts: [] hostNetwork: false hostPID: false volumes: []
apiVersion: v1 kind: ServiceAccount metadata: name: custom-scheduler namespace: kube-system
1 --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: custom-scheduler-as-kube-scheduler subjects: - kind: ServiceAccount name: custom-scheduler namespace: kube-system
2 roleRef: kind: ClusterRole name: system:kube-scheduler apiGroup: rbac.authorization.k8s.io --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: custom-scheduler-as-volume-scheduler subjects: - kind: ServiceAccount name: custom-scheduler namespace: kube-system
3 roleRef: kind: ClusterRole name: system:volume-scheduler apiGroup: rbac.authorization.k8s.io --- apiVersion: apps/v1 kind: Deployment metadata: labels: component: scheduler tier: control-plane name: custom-scheduler namespace: kube-system
4 spec: selector: matchLabels: component: scheduler tier: control-plane replicas: 1 template: metadata: labels: component: scheduler tier: control-plane version: second spec: serviceAccountName: custom-scheduler containers: - command: - /usr/local/bin/kube-scheduler - --address=0.0.0.0 - --leader-elect=false - --scheduler-name=custom-scheduler
5 image: "<namespace>/<image_name>:<tag>"
6 livenessProbe: httpGet: path: /healthz port: 10251 initialDelaySeconds: 15 name: kube-second-scheduler readinessProbe: httpGet: path: /healthz port: 10251 resources: requests: cpu: '0.1' securityContext: privileged: false volumeMounts: [] hostNetwork: false hostPID: false volumes: []
Copy to Clipboard Copied! クラスター内にデプロイメントリソースを作成します。
oc create -f custom-scheduler.yaml
$ oc create -f custom-scheduler.yaml
Copy to Clipboard Copied!
検証
スケジューラー Pod が実行されていることを確認します。
oc get pods -n kube-system
$ oc get pods -n kube-system
Copy to Clipboard Copied! カスタムスケジューラー Pod は
Running
として一覧表示されます。NAME READY STATUS RESTARTS AGE custom-scheduler-6cd7c4b8bc-854zb 1/1 Running 0 2m
NAME READY STATUS RESTARTS AGE custom-scheduler-6cd7c4b8bc-854zb 1/1 Running 0 2m
Copy to Clipboard Copied!
3.10.2. カスタムスケジューラーを使用した Pod のデプロイ
カスタムスケジューラーをクラスターにデプロイした後、デフォルトのスケジューラーではなくそのスケジューラーを使用するように Pod を設定できます。
各スケジューラーには、クラスター内のリソースの個別のビューがあります。このため、各スケジューラーは独自のノードセットを動作する必要があります。
2 つ以上のスケジューラーが同じノードで動作する場合、それらは互いに介入し、利用可能なリソースよりも多くの Pod を同じノードにスケジュールする可能性があります。この場合、Pod はリソースが十分にないために拒否される可能性があります。
前提条件
-
cluster-admin
ロールを持つユーザーとしてクラスターにアクセスできる。 - カスタムスケジューラーがクラスターにデプロイされている。
手順
クラスターがロールベースアクセス制御 (RBAC) を使用する場合は、カスタムスケジューラー名を
system:kube-scheduler
クラスターロールに追加します。system:kube-scheduler
クラスターロールを編集します。oc edit clusterrole system:kube-scheduler
$ oc edit clusterrole system:kube-scheduler
Copy to Clipboard Copied! カスタムスケジューラーの名前を、
leases
およびendpoints
リソースのresourceNames
一覧に追加します。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" uid: 53896c70-b332-420a-b2a4-f72c822313f2 rules: ... - apiGroups: - coordination.k8s.io resources: - leases verbs: - create - apiGroups: - coordination.k8s.io resourceNames: - kube-scheduler - custom-scheduler resources: - leases verbs: - get - update - apiGroups: - "" resources: - endpoints verbs: - create - apiGroups: - "" resourceNames: - kube-scheduler - custom-scheduler resources: - endpoints verbs: - get - update ...
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" uid: 53896c70-b332-420a-b2a4-f72c822313f2 rules: ... - apiGroups: - 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 - custom-scheduler
2 resources: - endpoints verbs: - get - update ...
Copy to Clipboard Copied!
Pod
設定を作成し、schedulerName
パラメーターでカスタムスケジューラーの名前を指定します。custom-scheduler-example.yaml
ファイルの例apiVersion: v1 kind: Pod metadata: name: custom-scheduler-example labels: name: custom-scheduler-example spec: schedulerName: custom-scheduler containers: - name: pod-with-second-annotation-container image: docker.io/ocpqe/hello-pod
apiVersion: 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
Copy to Clipboard Copied! - 1
- 使用するカスタムスケジューラーの名前です。この例では
custom-scheduler
になります。スケジューラー名が指定されていない場合、Pod はデフォルトのスケジューラーを使用して自動的にスケジュールされます。
Pod を作成します。
oc create -f custom-scheduler-example.yaml
$ oc create -f custom-scheduler-example.yaml
Copy to Clipboard Copied!
検証
以下のコマンドを入力し、Pod が作成されたことを確認します。
oc get pod custom-scheduler-example
$ oc get pod custom-scheduler-example
Copy to Clipboard Copied! custom-scheduler-example
Pod が出力に表示されます。NAME READY STATUS RESTARTS AGE custom-scheduler-example 1/1 Running 0 4m
NAME READY STATUS RESTARTS AGE custom-scheduler-example 1/1 Running 0 4m
Copy to Clipboard Copied! 以下のコマンドを入力し、カスタムスケジューラーが Pod をスケジュールしたことを確認します。
oc describe pod custom-scheduler-example
$ oc describe pod custom-scheduler-example
Copy to Clipboard Copied! 以下の切り捨てられた出力に示されるように、スケジューラー
custom-scheduler
が一覧表示されます。Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled <unknown> custom-scheduler Successfully assigned default/custom-scheduler-example to <node_name>
Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled <unknown> custom-scheduler Successfully assigned default/custom-scheduler-example to <node_name>
Copy to Clipboard Copied!