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.
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.
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)
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
Skipat 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.
@AxeZhan I test NodeResourcesBalancedAllocation with
nonZeroRequested, the requested (for cpu and memory) maybe larger than allocatable, and plugin will return score100for theoverflownode. see code below:https://github.com/kubernetes/kubernetes/blob/8a39b6062060ffb4fba52f53c011bd00428db194/pkg/scheduler/framework/plugins/noderesources/balanced_allocation.go#L145-L147.
scheduler logs:
@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