Resource Bin Packing for Extended Resources

    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.

    Kubernetes 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 and improves the utilization of scarce resources in large clusters. The behavior of the RequestedToCapacityRatioResourceAllocation priority function can be controlled by a configuration option called RequestedToCapacityRatioArgs. This argument consists of two parameters shape and resources. The shape parameter allows the user to tune the function as least requested or most requested based on utilization and score values. The resources parameter consists of name of 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.

    Referencing the KubeSchedulerConfiguration file with the kube-scheduler flag --config=/path/to/config/file will pass the configuration to the scheduler.

    This feature is disabled by default

    1. shape:
    2. - utilization: 0
    3. score: 0
    4. - utilization: 100
    5. 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. shape:
    2. - utilization: 0
    3. score: 10
    4. - utilization: 100
    5. score: 0

    is an optional parameter which defaults to:

    It can be used to add extended resources as follows:

    1. resources:
    2. - name: intel.com/foo
    3. weight: 5
    4. - name: cpu
    5. weight: 3
    6. - name: memory
    7. weight: 1

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

    Node scoring for capacity allocation

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

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

    Resource weights:

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

    Node 1 spec:

    1. Available:
    2. memory: 1 GB
    3. cpu: 8
    4. Used:
    5. intel.com/foo: 1
    6. memory: 256MB
    7. cpu: 1

    Node score:

    1. intel.com/foo = resourceScoringFunction((2+1),4)
    2. = (100 - ((4-3)*100/4)
    3. = (100 - 25)
    4. = 75 # requested + used = 75% * available
    5. = rawScoringFunction(75)
    6. = 7 # floor(75/10)
    7. memory = resourceScoringFunction((256+256),1024)
    8. = (100 -((1024-512)*100/1024))
    9. = 50 # requested + used = 50% * available
    10. = 5 # floor(50/10)
    11. cpu = resourceScoringFunction((2+1),8)
    12. = (100 -((8-3)*100/8))
    13. = 37.5 # requested + used = 37.5% * available
    14. = rawScoringFunction(37.5)
    15. = 3 # floor(37.5/10)
    16. NodeScore = (7 * 5) + (5 * 1) + (3 * 3) / (5 + 1 + 3)
    17. = 5

    Node 2 spec:

    1. intel.com/foo = resourceScoringFunction((2+2),8)
    2. = (100 - ((8-4)*100/8)
    3. = (100 - 50)
    4. = 50
    5. = rawScoringFunction(50)
    6. = 5
    7. memory = resourceScoringFunction((256+512),1024)
    8. = (100 -((1024-768)*100/1024))
    9. = 75
    10. = rawScoringFunction(75)
    11. = 7
    12. cpu = resourceScoringFunction((2+6),8)
    13. = (100 -((8-8)*100/8))
    14. = 100
    15. = rawScoringFunction(100)
    16. = 10
    17. NodeScore = (5 * 5) + (7 * 1) + (10 * 3) / (5 + 1 + 3)
    18. = 7

    What’s next