扩展资源的资源装箱

FEATURE STATE: Kubernetes 1.16 [alpha]

使用 RequestedToCapacityRatioResourceAllocation 优先级函数,可以将 kube-scheduler 配置为支持包含扩展资源在内的资源装箱操作。 优先级函数可用于根据自定义需求微调 kube-scheduler 。

使用 RequestedToCapacityRatioResourceAllocation 启用装箱

在 Kubernetes 1.15 之前,Kube-scheduler 通常允许根据对主要资源(如 CPU 和内存) 的请求数量和可用容量 之比率对节点评分。 Kubernetes 1.16 在优先级函数中添加了一个新参数,该参数允许用户指定资源以及每类资源的权重, 以便根据请求数量与可用容量之比率为节点评分。 这就使得用户可以通过使用适当的参数来对扩展资源执行装箱操作,从而提高了大型集群中稀缺资源的利用率。 RequestedToCapacityRatioResourceAllocation 优先级函数的行为可以通过名为 requestedToCapacityRatioArguments 的配置选项进行控制。 该标志由两个参数 shaperesources 组成。 shape 允许用户根据 utilizationscore 值将函数调整为最少请求 (least requested)或 最多请求(most requested)计算。 resources 包含由 nameweight 组成,name 指定评分时要考虑的资源, weight 指定每种资源的权重。

以下是一个配置示例,该配置将 requestedToCapacityRatioArguments 设置为对扩展资源 intel.com/foointel.com/bar 的装箱行为

  1. {
  2. "kind": "Policy",
  3. "apiVersion": "v1",
  4. ...
  5. "priorities": [
  6. ...
  7. {
  8. "name": "RequestedToCapacityRatioPriority",
  9. "weight": 2,
  10. "argument": {
  11. "requestedToCapacityRatioArguments": {
  12. "shape": [
  13. {"utilization": 0, "score": 0},
  14. {"utilization": 100, "score": 10}
  15. ],
  16. "resources": [
  17. {"name": "intel.com/foo", "weight": 3},
  18. {"name": "intel.com/bar", "weight": 5}
  19. ]
  20. }
  21. }
  22. }
  23. ],
  24. }

默认情况下此功能处于被禁用状态

调整 RequestedToCapacityRatioResourceAllocation 优先级函数

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

  1. {"utilization": 0, "score": 0},
  2. {"utilization": 100, "score": 10}

上面的参数在 utilization 为 0% 时给节点评分为 0,在 utilization 为 100% 时给节点评分为 10,因此启用了装箱行为。 要启用最少请求(least requested)模式,必须按如下方式反转得分值。

  1. {"utilization": 0, "score": 10},
  2. {"utilization": 100, "score": 0}

resources 是一个可选参数,默认情况下设置为:

  1. "resources": [
  2. {"name": "CPU", "weight": 1},
  3. {"name": "Memory", "weight": 1}
  4. ]

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

  1. "resources": [
  2. {"name": "intel.com/foo", "weight": 5},
  3. {"name": "CPU", "weight": 3},
  4. {"name": "Memory", "weight": 1}
  5. ]

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

RequestedToCapacityRatioResourceAllocation 优先级函数如何对节点评分

本节适用于希望了解此功能的内部细节的人员。 以下是如何针对给定的一组值来计算节点得分的示例。

  1. 请求的资源
  2. intel.com/foo: 2
  3. Memory: 256MB
  4. CPU: 2
  5. 资源权重
  6. intel.com/foo: 5
  7. Memory: 1
  8. CPU: 3
  9. FunctionShapePoint {{0, 0}, {100, 10}}
  10. 节点 Node 1 配置
  11. 可用:
  12. intel.com/foo : 4
  13. Memory : 1 GB
  14. CPU: 8
  15. 已用:
  16. intel.com/foo: 1
  17. Memory: 256MB
  18. CPU: 1
  19. 节点得分:
  20. intel.com/foo = resourceScoringFunction((2+1),4)
  21. = (100 - ((4-3)*100/4)
  22. = (100 - 25)
  23. = 75
  24. = rawScoringFunction(75)
  25. = 7
  26. Memory = resourceScoringFunction((256+256),1024)
  27. = (100 -((1024-512)*100/1024))
  28. = 50
  29. = rawScoringFunction(50)
  30. = 5
  31. CPU = resourceScoringFunction((2+1),8)
  32. = (100 -((8-3)*100/8))
  33. = 37.5
  34. = rawScoringFunction(37.5)
  35. = 3
  36. NodeScore = (7 * 5) + (5 * 1) + (3 * 3) / (5 + 1 + 3)
  37. = 5
  38. 节点 Node 2 配置
  39. 可用:
  40. intel.com/foo: 8
  41. Memory: 1GB
  42. CPU: 8
  43. 已用:
  44. intel.com/foo: 2
  45. Memory: 512MB
  46. CPU: 6
  47. 节点得分:
  48. intel.com/foo = resourceScoringFunction((2+2),8)
  49. = (100 - ((8-4)*100/8)
  50. = (100 - 50)
  51. = 50
  52. = rawScoringFunction(50)
  53. = 5
  54. Memory = resourceScoringFunction((256+512),1024)
  55. = (100 -((1024-768)*100/1024))
  56. = 75
  57. = rawScoringFunction(75)
  58. = 7
  59. CPU = resourceScoringFunction((2+6),8)
  60. = (100 -((8-8)*100/8))
  61. = 100
  62. = rawScoringFunction(100)
  63. = 10
  64. NodeScore = (5 * 5) + (7 * 1) + (10 * 3) / (5 + 1 + 3)
  65. = 7