启用 Kubernetes 自定义调度器的所有默认插件
本文说明如何修改 Kubernetes 自定义调度器(基于 v1.27.0),启用所有默认插件,同时保留自定义 CustomFilter
插件,以解决因缺失插件(如 VolumeBinding
)导致的调度错误。错误示例:
E0416 17:24:39.383376 69619 framework.go:1153] "Failed running Reserve plugin" err="not found" plugin="VolumeBinding" pod="default/pulsar-manager-deployment-545fbfd94b-zhzrc"
E0416 17:24:39.383444 69619 schedule_one.go:883] "Error scheduling pod; retrying" err="running Reserve plugin \"VolumeBinding\": not found" pod="default/pulsar-manager-deployment-545fbfd94b-zhzrc"
前提条件
- 已实现并编译自定义调度器(
custom-scheduler
),包含CustomFilter
插件。 - 调度器配置文件路径:
/Users/liyinlong/goproject/openmiddleware-scheduler/resources/scheduler-config.yaml
。 - Kubeconfig 文件有效:
/Users/liyinlong/istioproject/env/88.conf
。 - Kubernetes 集群版本:v1.27.0。
背景
Kubernetes 调度器的默认插件涵盖 PreFilter
、Filter
、Score
、Reserve
、Permit
、PreBind
和 Bind
阶段,处理资源分配、存储卷绑定、节点亲和性等功能。在 v1.27.0 中,默认插件包括 NodeResourcesFit
、VolumeBinding
、NodeAffinity
、DefaultBinder
等。之前的配置禁用了所有默认插件,导致 VolumeBinding
缺失,无法调度使用 PVC 的 Pod(如 pulsar-manager-deployment
)。
启用所有默认插件的步骤
以下是如何启用默认插件并整合 CustomFilter
的详细步骤。
1. 修改调度器配置文件
编辑 /Users/liyinlong/goproject/openmiddleware-scheduler/resources/scheduler-config.yaml
,移除禁用默认插件的配置,仅添加 CustomFilter
到 Filter 阶段:
apiVersion: kubescheduler.config.k8s.io/v1beta2
kind: KubeSchedulerConfiguration
profiles:
- schedulerName: custom-scheduler
plugins:
filter:
enabled:
- name: CustomFilter
说明:
- 移除禁用配置:不使用
disabled: - name: "*"
,启用所有默认插件(如VolumeBinding
、NodeResourcesFit
、NodeAffinity
等)。 - 添加 CustomFilter:在
filter
阶段的enabled
列表中添加CustomFilter
,与默认 Filter 插件一起运行。 - 其他阶段:不显式配置
preFilter
、score
、reserve
、bind
等阶段,使用 Kubernetes v1.27.0 默认插件集。 - apiVersion:保留
v1beta2
(v1.27.0 支持),后续可升级到v1beta3
。
默认插件(v1.27.0 部分列表):
- PreFilter:
NodeResourcesFit
,NodePorts
,VolumeBinding
,PodTopologySpread
- Filter:
NodeResourcesFit
,NodePorts
,NodeAffinity
,VolumeBinding
- Score:
NodeResourcesFit
,ImageLocality
,TaintToleration
- Reserve:
VolumeBinding
- Bind:
DefaultBinder
启用默认插件后,VolumeBinding
自动包含,解决报错。
2. 验证配置文件
确认 scheduler-config.yaml
内容:
cat /Users/liyinlong/goproject/openmiddleware-scheduler/resources/scheduler-config.yaml
确保仅在 filter
阶段添加了 CustomFilter
,未禁用其他插件。
3. 运行调度器
运行调度器:
./custom-scheduler --config=/Users/liyinlong/goproject/openmiddleware-scheduler/resources/scheduler-config.yaml --kubeconfig=/Users/liyinlong/istioproject/env/88.conf --bind-address=127.0.0.1
检查点:
确保可执行文件是
./custom-scheduler
。验证 kubeconfig 文件有效:
kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf cluster-info
预期结果:
- 调度器启动时不再报
VolumeBinding
插件缺失的错误。 - 日志可能显示
CustomFilter
的执行信息(如Node <node-name> passed custom filter
)。
4. 确认 RBAC 权限
启用所有默认插件后,调度器需要更广泛的权限。更新 scheduler-rbac.yaml
:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: custom-scheduler-role
rules:
- apiGroups: [""]
resources: ["nodes", "pods", "configmaps", "events", "persistentvolumeclaims", "persistentvolumes"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["pods/binding"]
verbs: ["create"]
- apiGroups: [""]
resources: ["pods/status"]
verbs: ["update"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["services", "endpoints"]
verbs: ["get", "list", "watch"]
- apiGroups: ["policy"]
resources: ["poddisruptionbudgets"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: custom-scheduler-binding
subjects:
- kind: User
name: <kubeconfig-username> # 替换为实际用户名
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: custom-scheduler-role
apiGroup: rbac.authorization.k8s.io
替换用户名:
查看 kubeconfig 用户名:
kubectl config view --kubeconfig=/Users/liyinlong/istioproject/env/88.conf -o jsonpath='{.users[*].name}'
更新
subjects.name
。
应用 RBAC:
kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf apply -f scheduler-rbac.yaml
5. 测试调度器
为节点添加标签:
kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf label nodes <node-name> scheduler.custom/enabled=true
重新应用 Pod:
删除并重新创建失败的 Pod:
kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf delete pod pulsar-manager-deployment-545fbfd94b-zhzrc kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf apply -f <pulsar-manager-deployment.yaml>
或创建测试 Pod:
apiVersion: v1 kind: Pod metadata: name: test-pod spec: schedulerName: custom-scheduler containers: - name: nginx image: nginx
应用:
kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf apply -f test-pod.yaml
验证调度结果:
kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf get pods -o wide
检查日志(终端输出):
Node <node-name> passed custom filter
验证 PVC(如果适用):
kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf get pvc kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf get pv
6. 处理 KubeSchedulerConfiguration 版本警告(可选)
日志中的 v1beta2
警告可通过升级到 v1beta3
解决:
apiVersion: kubescheduler.config.k8s.io/v1beta3
kind: KubeSchedulerConfiguration
profiles:
- schedulerName: custom-scheduler
plugins:
filter:
enabled:
- name: CustomFilter
重新运行:
./custom-scheduler --config=/Users/liyinlong/goproject/openmiddleware-scheduler/resources/scheduler-config.yaml --kubeconfig=/Users/liyinlong/istioproject/env/88.conf --bind-address=127.0.0.1
注意:确认 v1.27.0 支持 v1beta3
(参考 Kubernetes 文档)。如有问题,保留 v1beta2
。
7. 常见问题与解决方案
错误:其他插件缺失:
- 检查
scheduler-config.yaml
是否意外禁用插件。 - 恢复默认配置(仅添加
CustomFilter
)。
- 检查
错误:PVC 未绑定:
检查 PVC/PV:
kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf get pvc kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf get pv
确认动态存储或创建匹配的 PV。
错误:权限不足:
验证 RBAC:
kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf get clusterrole custom-scheduler-role kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf get clusterrolebinding custom-scheduler-binding
Pod 未调度:
检查日志(终端)。
确认节点标签:
kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf get nodes --show-labels
查看 Pod 事件:
kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf describe pod pulsar-manager-deployment-545fbfd94b-zhzrc
总结
通过移除 scheduler-config.yaml
中的禁用配置,启用所有默认插件,并添加 CustomFilter
,可解决 VolumeBinding
缺失问题。更新后的调度器支持完整调度流程,适用于包含 PVC 的 Pod。确保 RBAC 权限覆盖所有资源。
如有问题,提供以下信息:
- 修改后的
scheduler-config.yaml
。 kubectl --kubeconfig=/Users/liyinlong/istioproject/env/88.conf describe pod pulsar-manager-deployment-545fbfd94b-zhzrc
输出。/Users/liyinlong/istioproject/env/88.conf
内容(敏感信息可隐藏)。