资源分箱

在 kube-scheduler 的 scheduling-plugin NodeResourcesFit 中,有两种支持资源装箱的评分策略:MostAllocatedRequestedToCapacityRatio

使用 MostAllocated 策略启用装箱

MostAllocated 策略根据资源的利用率对节点进行评分,优先考虑分配率较高的节点。对于每种资源类型,您可以设置权重来修改其对节点评分的影响。

要为 NodeResourcesFit 插件设置 MostAllocated 策略,请使用类似于以下内容的 调度器配置

apiVersion: kubescheduler.config.k8s.io/v1
kind: KubeSchedulerConfiguration
profiles:
- pluginConfig:
  - args:
      scoringStrategy:
        resources:
        - name: cpu
          weight: 1
        - name: memory
          weight: 1
        - name: intel.com/foo
          weight: 3
        - name: intel.com/bar
          weight: 3
        type: MostAllocated
    name: NodeResourcesFit

要详细了解其他参数及其默认配置,请参阅 NodeResourcesFitArgs 的 API 文档。

使用 RequestedToCapacityRatio 启用装箱

RequestedToCapacityRatio 策略允许用户指定资源以及每种资源的权重,以便根据请求容量比对节点进行评分。这允许用户通过使用适当的参数对扩展资源进行装箱,以提高大型集群中稀缺资源的利用率。它根据已分配资源的配置函数来选择节点。可以通过 scoringStrategy 字段来控制 NodeResourcesFit 评分函数中 RequestedToCapacityRatio 的行为。在 scoringStrategy 字段中,您可以配置两个参数:requestedToCapacityRatioresourcesrequestedToCapacityRatio 参数中的 shape 允许用户根据 utilizationscore 值将函数调整为最少请求或最多请求。resources 参数包括在评分过程中要考虑的资源的 name 及其相应的 weight,它指定每种资源的权重。

以下是一个示例配置,该配置使用 requestedToCapacityRatio 字段为扩展资源 intel.com/foointel.com/bar 设置装箱行为。

apiVersion: kubescheduler.config.k8s.io/v1
kind: KubeSchedulerConfiguration
profiles:
- pluginConfig:
  - args:
      scoringStrategy:
        resources:
        - name: intel.com/foo
          weight: 3
        - name: intel.com/bar
          weight: 3
        requestedToCapacityRatio:
          shape:
          - utilization: 0
            score: 0
          - utilization: 100
            score: 10
        type: RequestedToCapacityRatio
    name: NodeResourcesFit

使用 kube-scheduler 标志 --config=/path/to/config/file 引用 KubeSchedulerConfiguration 文件会将配置传递给调度器。

要详细了解其他参数及其默认配置,请参阅 NodeResourcesFitArgs 的 API 文档。

调整评分函数

shape 用于指定 RequestedToCapacityRatio 函数的行为。

shape:
  - utilization: 0
    score: 0
  - utilization: 100
    score: 10

以上参数在 utilization 为 0% 时为节点提供 0 的 score,在 utilization 为 100% 时为节点提供 10 的 score,从而启用装箱行为。要启用最少请求,必须反转分数值,如下所示。

shape:
  - utilization: 0
    score: 10
  - utilization: 100
    score: 0

resources 是一个可选参数,默认为

resources:
  - name: cpu
    weight: 1
  - name: memory
    weight: 1

它可以用来添加扩展资源,如下所示

resources:
  - name: intel.com/foo
    weight: 5
  - name: cpu
    weight: 3
  - name: memory
    weight: 1

weight 参数是可选的,如果未指定,则设置为 1。此外,weight 不能设置为负值。

容量分配的节点评分

本节面向那些希望了解此功能内部细节的人员。以下是针对给定值集计算节点分数的示例。

请求的资源

intel.com/foo : 2
memory: 256MB
cpu: 2

资源权重

intel.com/foo : 5
memory: 1
cpu: 3

FunctionShapePoint {{0, 0}, {100, 10}}

节点 1 规格

Available:
  intel.com/foo: 4
  memory: 1 GB
  cpu: 8

Used:
  intel.com/foo: 1
  memory: 256MB
  cpu: 1

节点分数

intel.com/foo  = resourceScoringFunction((2+1),4)
               = (100 - ((4-3)*100/4)
               = (100 - 25)
               = 75                       # requested + used = 75% * available
               = rawScoringFunction(75)
               = 7                        # floor(75/10)

memory         = resourceScoringFunction((256+256),1024)
               = (100 -((1024-512)*100/1024))
               = 50                       # requested + used = 50% * available
               = rawScoringFunction(50)
               = 5                        # floor(50/10)

cpu            = resourceScoringFunction((2+1),8)
               = (100 -((8-3)*100/8))
               = 37.5                     # requested + used = 37.5% * available
               = rawScoringFunction(37.5)
               = 3                        # floor(37.5/10)

NodeScore   =  ((7 * 5) + (5 * 1) + (3 * 3)) / (5 + 1 + 3)
            =  5

节点 2 规格

Available:
  intel.com/foo: 8
  memory: 1GB
  cpu: 8
Used:
  intel.com/foo: 2
  memory: 512MB
  cpu: 6

节点分数

intel.com/foo  = resourceScoringFunction((2+2),8)
               =  (100 - ((8-4)*100/8)
               =  (100 - 50)
               =  50
               =  rawScoringFunction(50)
               = 5

memory         = resourceScoringFunction((256+512),1024)
               = (100 -((1024-768)*100/1024))
               = 75
               = rawScoringFunction(75)
               = 7

cpu            = resourceScoringFunction((2+6),8)
               = (100 -((8-8)*100/8))
               = 100
               = rawScoringFunction(100)
               = 10

NodeScore   =  ((5 * 5) + (7 * 1) + (10 * 3)) / (5 + 1 + 3)
            =  7

下一步

上次修改时间:2024 年 2 月 19 日下午 1:54 PST:修复调度器部分中的尾随空格 (2f298d2077)