02 - Multiple Schedulers
Kubernetes Multiple Schedulers
📌 為什麼需要多個 Scheduler?
Kubernetes 預設使用 kube-scheduler 處理所有 Pod 的排程任務。
但某些場景下,我們可能需要:
- 使用不同策略排程不同類型的工作負載(ex: ML Job、批次任務)
- 為特定隊列、優先級、資源需求定制排程邏輯
- 測試自定義排程演算法(研究用)
⚙️ 如何實作 Multiple Schedulers?
在 cluster 中「同時部署多個 scheduler」,然後讓特定 Pod 使用你指定的 scheduler 名稱進行排程。
1️⃣ 設計你的排程架構
- 使用原生 default-scheduler 處理一般 workload
- 使用 custom-scheduler 處理 ML/批次任務
- 未來可能擴充更多 scheduler
2️⃣ 撰寫或部署自定義 Scheduler
可以是:
- Fork 官方 kube-scheduler 修改排程邏輯(進階)
- 用 Go/Python 等語言實作一個簡單的排程邏輯
- 或使用現成的開源方案(如 Volcano、YuniKorn)
建立自定義 Scheduler 後,打包為 Docker Image。
3️⃣ 部署到 Kubernetes
以一個最簡單的 custom scheduler 為例(custom-scheduler-deploy.yaml):
apiVersion: apps/v1
kind: Deployment
metadata:
name: custom-scheduler
spec:
replicas: 1
selector:
matchLabels:
component: custom-scheduler
template:
metadata:
labels:
component: custom-scheduler
spec:
containers:
- name: custom-scheduler
image: yourname/custom-scheduler:latest
env:
4️⃣ 建立測試 `example-pod` Pod 使用自訂 Scheduler
apiVersion: v1
kind: Pod
metadata:
name: example-pod
spec:
schedulerName: custom-scheduler
containers:
- name: busybox
image: busybox
command: ["sleep", "3600"]
5️⃣ 驗證 Pod 是否被正確排程
$ kubectl get pods -o wide
We have already created the `ServiceAccount` and `ClusterRoleBinding` that our custom scheduler will make use of.
Checkout the following Kubernetes objects:
- ServiceAccount: my-scheduler (kube-system namespace)
- ClusterRoleBinding: my-scheduler-as-kube-scheduler
- ClusterRoleBinding: my-scheduler-as-volume-scheduler
$ kubectl get sa my-scheduler -n kube-system
$ kubectl get sa -n kube-system
$ kubectl get clusterrolebinding
Q: Let's create a configmap that the new scheduler will employ using the concept of `ConfigMap as a volume`.
Use the imperative command `kubectl create -f` to create the configMap from the given definition file.
$ kubectl create -f /root/my-scheduler-configmap.yaml
or$ kubectl create configmap my-scheduler-config --from-file=/root/my-scheduler-config.yaml -n kube-system
$ kubectl get configmap my-scheduler-config -n kube-system
Q: Deploy an additional scheduler to the cluster following the given specification.
- Name: my-scheduler
- Status: Running
- Correct image used?
$ kubectl describe pod kube-scheduler-controlplane --namespace=kube-system | grep -i 'image'
$ kubectl create -f my-scheduler.yaml
Q: A POD definition file is given. Use it to create a POD with the new custom scheduler.
- Uses custom scheduler
- Status: Running






留言
張貼留言