• Resource Bin Packing for Extended Resources
    • Enabling Bin Packing using RequestedToCapacityRatioResourceAllocation
      • Tuning RequestedToCapacityRatioResourceAllocation Priority Function
      • How the RequestedToCapacityRatioResourceAllocation Priority Function Scores Nodes
    • Feedback

    Resource Bin Packing for Extended Resources

    FEATURE STATE: Kubernetes 1.16alphaThis feature is currently in a alpha state, meaning:

    • The version names contain alpha (e.g. v1alpha1).
    • Might be buggy. Enabling the feature may expose bugs. Disabled by default.
    • Support for feature may be dropped at any time without notice.
    • The API may change in incompatible ways in a later software release without notice.
    • Recommended for use only in short-lived testing clusters, due to increased risk of bugs and lack of long-term support.

    The kube-scheduler can be configured to enable bin packing of resources along with extended resources using RequestedToCapacityRatioResourceAllocation priority function. Priority functions can be used to fine-tune the kube-scheduler as per custom needs.

    Enabling Bin Packing using RequestedToCapacityRatioResourceAllocation

    Before Kubernetes 1.15, Kube-scheduler used to allow scoring nodes based on the request to capacity ratio of primary resources like CPU and Memory. Kubernetes 1.16 added a new parameter to the priority function that allows the users to specify the resources along with weights for each resource to score nodes based on the request to capacity ratio. This allows users to bin pack extended resources by using appropriate parameters improves the utilization of scarce resources in large clusters. The behavior of the RequestedToCapacityRatioResourceAllocation priority function can be controlled by a configuration option called requestedToCapacityRatioArguments. This argument consists of two parameters shape and resources. Shape allows the user to tune the function as least requested or most requested based on utilization and score values. Resourcesconsists of name which specifies the resource to be considered during scoring and weight specify the weight of each resource.

    Below is an example configuration that sets requestedToCapacityRatioArguments to bin packing behavior for extended resources intel.com/foo and intel.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. }

    This feature is disabled by default

    Tuning RequestedToCapacityRatioResourceAllocation Priority Function

    shape is used to specify the behavior of the RequestedToCapacityRatioPriority function.

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

    The above arguments give the node a score of 0 if utilization is 0% and 10 for utilization 100%, thus enabling bin packing behavior. To enable least requested the score value must be reversed as follows.

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

    resources is an optional parameter which by defaults is set to:

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

    It can be used to add extended resources as follows:

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

    The weight parameter is optional and is set to 1 if not specified. Also, the weight cannot be set to a negative value.

    How the RequestedToCapacityRatioResourceAllocation Priority Function Scores Nodes

    This section is intended for those who want to understand the internal detailsof this feature.Below is an example of how the node score is calculated for a given set of values.

    1. Requested Resources
    2. intel.com/foo : 2
    3. Memory: 256MB
    4. CPU: 2
    5. Resource Weights
    6. intel.com/foo : 5
    7. Memory: 1
    8. CPU: 3
    9. FunctionShapePoint {{0, 0}, {100, 10}}
    10. Node 1 Spec
    11. Available:
    12. intel.com/foo : 4
    13. Memory : 1 GB
    14. CPU: 8
    15. Used:
    16. intel.com/foo: 1
    17. Memory: 256MB
    18. CPU: 1
    19. Node Score:
    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 Spec
    39. Available:
    40. intel.com/foo: 8
    41. Memory: 1GB
    42. CPU: 8
    43. Used:
    44. intel.com/foo: 2
    45. Memory: 512MB
    46. CPU: 6
    47. Node Score:
    48. intel.com/foo = resourceScoringFunction((2+2),8)
    49. = (100 - ((8-4)*100/8)
    50. = (100 - 25)
    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

    Feedback

    Was this page helpful?

    Thanks for the feedback. If you have a specific, answerable question about how to use Kubernetes, ask it onStack Overflow.Open an issue in the GitHub repo if you want toreport a problemorsuggest an improvement.