彻底搞懂kubernetes调度框架与插件

打印 上一主题 下一主题

主题 555|帖子 555|积分 1665

调度框架 [1]

本文基于 kubernetes 1.24 进行分析
调度框架(Scheduling Framework)是Kubernetes 的调度器 kube-scheduler 设计的的可插拔架构,将插件(调度算法)嵌入到调度上下文的每个扩展点中,并编译为 kube-scheduler
在 kube-scheduler 1.22 之后,在 pkg/scheduler/framework/interface.go 中定义了一个 Plugininterface,这个 interface 作为了所有插件的父级。而每个未调度的 Pod,Kubernetes 调度器会根据一组规则尝试在集群中寻找一个节点。
  1. type Plugin interface {
  2.         Name() string
  3. }
复制代码
下面会对每个算法是如何实现的进行分析
在初始化 scheduler 时,会创建一个 profile,profile是关于 scheduler 调度配置相关的定义
  1. func New(client clientset.Interface,
  2. ...
  3.         profiles, err := profile.NewMap(options.profiles, registry, recorderFactory, stopCh,
  4.                 frameworkruntime.WithComponentConfigVersion(options.componentConfigVersion),
  5.                 frameworkruntime.WithClientSet(client),
  6.                 frameworkruntime.WithKubeConfig(options.kubeConfig),
  7.                 frameworkruntime.WithInformerFactory(informerFactory),
  8.                 frameworkruntime.WithSnapshotSharedLister(snapshot),
  9.                 frameworkruntime.WithPodNominator(nominator),
  10.                 frameworkruntime.WithCaptureProfile(frameworkruntime.CaptureProfile(options.frameworkCapturer)),
  11.                 frameworkruntime.WithClusterEventMap(clusterEventMap),
  12.                 frameworkruntime.WithParallelism(int(options.parallelism)),
  13.                 frameworkruntime.WithExtenders(extenders),
  14.         )
  15.         if err != nil {
  16.                 return nil, fmt.Errorf("initializing profiles: %v", err)
  17.         }
  18.         if len(profiles) == 0 {
  19.                 return nil, errors.New("at least one profile is required")
  20.         }
  21. ....
  22. }
复制代码
关于 profile 的实现,则为 KubeSchedulerProfile,也是作为 yaml生成时传入的配置
  1. // KubeSchedulerProfile 是一个 scheduling profile.
  2. type KubeSchedulerProfile struct {
  3.     // SchedulerName 是与此配置文件关联的调度程序的名称。
  4.     // 如果 SchedulerName 与 pod “spec.schedulerName”匹配,则使用此配置文件调度 pod。
  5.         SchedulerName string
  6.     // Plugins指定应该启用或禁用的插件集。
  7.     // 启用的插件是除了默认插件之外应该启用的插件。禁用插件应是禁用的任何默认插件。
  8.     // 当没有为扩展点指定启用或禁用插件时,将使用该扩展点的默认插件(如果有)。
  9.     // 如果指定了 QueueSort 插件,
  10.     // 则必须为所有配置文件指定相同的 QueueSort Plugin 和 PluginConfig。
  11.     // 这个Plugins展现的形式则是调度上下文中的所有扩展点(这是抽象),实际中会表现为多个扩展点
  12.         Plugins *Plugins
  13.         // PluginConfig 是每个插件的一组可选的自定义插件参数。
  14.     // 如果省略PluginConfig参数等同于使用该插件的默认配置。
  15.         PluginConfig []PluginConfig
  16. }
复制代码
对于 profile.NewMap 就是根据给定的配置来构建这个framework,因为配置可能是存在多个的。而 Registry 则是所有可用插件的集合,内部构造则是 PluginFactory ,通过函数来构建出对应的 plugin
[code]func NewMap(cfgs []config.KubeSchedulerProfile, r frameworkruntime.Registry, recorderFact RecorderFactory,        stopCh
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

大号在练葵花宝典

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表