资源装箱
在 kube-scheduler 的 调度插件 NodeResourcesFit
中,有两种评分策略支持资源的 bin packing:MostAllocated
和 RequestedToCapacityRatio
。
使用 MostAllocated 策略启用 bin packing
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 启用 bin packing
RequestedToCapacityRatio
策略允许用户指定资源及其权重,以便根据请求容量比对节点进行评分。这使得用户可以通过使用适当的参数来 bin pack 扩展资源,从而提高大型集群中稀缺资源的利用率。它根据已分配资源的配置函数来偏好节点。RequestedToCapacityRatio
在 NodeResourcesFit
评分函数中的行为可以通过 scoringStrategy 字段进行控制。在 scoringStrategy
字段内,你可以配置两个参数:requestedToCapacityRatio
和 resources
。requestedToCapacityRatio
参数中的 shape
允许用户根据 utilization
和 score
值将函数调整为最少请求或最多请求。resources
参数包含在评分过程中要考虑的资源的 name
及其相应的 weight
,后者指定了每种资源的权重。
下面是一个示例配置,它使用 requestedToCapacityRatio
字段为扩展资源 intel.com/foo
和 intel.com/bar
设置 bin packing 行为。
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 分,在 utilization
为 100% 时获得 10 分,从而实现 bin packing 行为。要启用最少请求 (least requested),分数必须按如下方式反转。
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