kubernetes: NodeResourcesBalancedAllocation does not "Favors nodes that would obtain a more balanced resource usage if the Pod is scheduled there"

What would you like to be added?

The doc says:

NodeResourcesBalancedAllocation: Favors nodes that would obtain a more balanced resource usage if the Pod is scheduled there.

But reading at the code it:

Favors nodes that would obtain the most balanced resource usage once the Pod is scheduled there.

It would be good to have a plugin that scores according to how the balancing improves.

i.e.

instead of calculating score like this:

S_1 = 100 - 100 * abs \left( \frac{\text{node memory requests} + \text{pod memory request}}{\text{node memory allocatable}} - \frac{\text{node cpu requests} + \text{pod cpu request}}{node cpu allocatable} \right) / 2

calculate the ratio improvement, by first calculating ratio before the pod is scheduled:


S_2 = 100 - 100 * abs \left( \frac{\text{node memory requests}}{\text{node memory allocatable}} - \frac{\text{node cpu requests}}{node cpu allocatable} \right) / 2

And measuring the improvement

S = max (0, S_1 - S_2)

Note: the formula here is incorrect and can be reduced, but you have the idea.

Bonus: Here is a prometheus query to calculate the score (NB: you need to add requested resources to have the exact value):

100
-
100
*
abs(
    (
        (
            sum(cluster:namespace:pod_memory:active:kube_pod_container_resource_requests)
            by (node)
            /
            sum(kube_node_status_allocatable{resource="memory"}) by (node)
        )

        -
        (
            sum(cluster:namespace:pod_cpu:active:kube_pod_container_resource_requests)
            by (node)
            /
            sum(kube_node_status_allocatable{resource="cpu"}) by (node)
        )
    )
    /
    2
)

Why is this needed?

When scheduling a pod that is well balanced, the already well balanced nodes are favoured.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (11 by maintainers)

Most upvoted comments

I bet we could come up with various edge cases where both logics show their strengths or weaknesses (especially when we consider nearly empty vs nearly full nodes), but maximizing a balance improvement (as proposed here) seems a bit more reasonable approach (and aligned with the documentation).

It does make sense to me.

/cc @macsko @dom4ha @Huang-Wei @alculquicondor