kubernetes: NodeResourcesBalancedAllocation cause too many pods scheduled to the same node

What happened?

NodeResourcesBalancedAllocation will return different score if pod request is empty.

I1210 06:42:54.701779       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/task-worker-9" node="10.20.96.50" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727588291] requestedResource=map[cpu:14580 memory:24593301504] resourceScore=96
I1210 06:42:54.701793       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/task-worker-9" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:15350 memory:24235737088] resourceScore=92
I1210 06:42:54.701807       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/task-worker-9" node="10.20.96.9" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:13480 memory:19474153472] resourceScore=90

What did you expect to happen?

NodeResourcesBalancedAllocation score should return zero if podRequest is zero.

https://github.com/kubernetes/kubernetes/blob/a499facee693a1a83daadb82d88f7b51d324ffc5/pkg/scheduler/framework/plugins/noderesources/resource_allocation.go#L85-L114

The code below use IsPrefixedNativeResource, which ignore cpu and memory. https://github.com/kubernetes/kubernetes/blob/a499facee693a1a83daadb82d88f7b51d324ffc5/pkg/scheduler/util/utils.go#L158-L162

I think we should use below function.

https://github.com/kubernetes/kubernetes/blob/a499facee693a1a83daadb82d88f7b51d324ffc5/pkg/apis/core/v1/helper/helpers.go#L54-L60

How can we reproduce it (as minimally and precisely as possible)?

create pod whcih request is empty and enable NodeResourcesBalancedAllocation.

scheduler config:

- name: NodeResourcesBalancedAllocation
  args:
    resources:
      - name: cpu
      - name: memory

Anything else we need to know?

No response

Kubernetes version

$ kubectl version
# paste output here
Server Version: v1.24.15

Cloud provider

vanilla

OS version

# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, …) and versions (if applicable)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 55 (55 by maintainers)

Most upvoted comments

Ah, I was missing one thing; Pod topology spread has a built-in default constraints. So, for an even spreading direction, yes, it’s one option to just return 0 score, expecting this default Pod topology spread would spread zero-request pods (belonging to the same deployment) evenly, to some extent. Looks the simplest hence safest solution.

The best fix is to return Skip at PreScore when the pod’s request is 0, instead of reverting.

Before delving into the technical details, I’d like to take a step back and better understand the user scenario and motivation behind “running a large number of best-efforts pods”. In a real-world k8s cluster (prod/staging/test), I’m curious about the purpose of: a) running a large number of best-efforts pods, while also b) expecting them to be distributed evenly.

I checked https://github.com/kubernetes/kubernetes/pull/105845 and I’m not sure why we stop using nonZeroRequested in NodeResourcesBalancedAllocation. https://github.com/kubernetes/kubernetes/pull/102925 says it’s because too many zero requested containers can result in a huge nonZeroRequest and thus influence the schedule result.

@AxeZhan I test NodeResourcesBalancedAllocation with nonZeroRequested, the requested (for cpu and memory) maybe larger than allocatable, and plugin will return score 100 for the overflow node. see code below:

https://github.com/kubernetes/kubernetes/blob/8a39b6062060ffb4fba52f53c011bd00428db194/pkg/scheduler/framework/plugins/noderesources/balanced_allocation.go#L145-L147.

scheduler logs:

I1211 07:27:28.840885       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-4" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:20150 memory:34616639488] resourceScore=100
I1211 07:27:28.841500       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-40" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:20250 memory:34826354688] resourceScore=100
I1211 07:27:28.842080       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-41" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:20350 memory:35036069888] resourceScore=100
I1211 07:27:28.842676       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-42" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:20450 memory:35245785088] resourceScore=100
I1211 07:27:28.843178       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-43" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:20550 memory:35455500288] resourceScore=100
I1211 07:27:28.843733       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-44" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:20650 memory:35665215488] resourceScore=100
I1211 07:27:28.844389       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-45" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:20750 memory:35874930688] resourceScore=100
I1211 07:27:28.845017       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-46" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:20850 memory:36084645888] resourceScore=100
I1211 07:27:28.845602       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-47" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:20950 memory:36294361088] resourceScore=100
I1211 07:27:28.846116       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-48" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:21050 memory:36504076288] resourceScore=100
I1211 07:27:28.847625       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-5" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:21150 memory:36713791488] resourceScore=100
I1211 07:27:28.848933       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-6" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:21250 memory:36923506688] resourceScore=100
I1211 07:27:28.849620       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-7" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:21350 memory:37133221888] resourceScore=100
I1211 07:27:28.850208       1 resource_allocation.go:70] "Listing internal info for allocatable resources, requested resources and score" pod="tuyaco-k8s/hongqi-update-task-worker-8" node="10.20.96.8" resourceAllocationScorer="NodeResourcesBalancedAllocation" allocatableResource=map[cpu:15600 memory:28727600579] requestedResource=map[cpu:21450 memory:37342937088] resourceScore=100

the requested resources of a node will be updated with a default value if the pod has no requests.

@AxeZhan You are right, but the NodeResourcesBalancedAllocation plugin use real requestedResource.

see #105845. https://github.com/kubernetes/kubernetes/blob/a499facee693a1a83daadb82d88f7b51d324ffc5/pkg/scheduler/framework/plugins/noderesources/balanced_allocation.go#L132