Kubernetes version: 1.20
Cloud being used: Bare metal
Installation method: Kubeadm
Host OS: Redhat
We have a 7 node cluster and have the following requirements:
Deploy specific application pods to 2 nodes only
Enure the 2 nodes have enough memory/cpu before deploying them.
For #1, we tainted the two nodes, added the tolerations as well as node affinity to our statefulsets/deployments so no other pods are allowed to run besides our application.
For #2, one of the nodes keeps crashing because the scheudler is deploying pods even though memory/cpu is over 80% and the other node is less that 30% memory/cpu.
I don’t understand why this is happening but suspect it’s because for some reason the scheduler is coming up with a score based on the entire cluster and not the two nodes we’re interested in.
Does anyone know if it’s possible to configure a custom kube-scheduler to focus on two nodes only ? I think this is the only way to achieve a balance.
Thanks but isn’t this the same thing as node affinity (which is a little more advanced) ? We have given the same label to each of the two nodes and the scheduler isn’t distributing to any of the other 5 nodes (as intended) but it doesn’t seem to take high memory into account when placing new pods so one of the two nodes eventually falls over.
Thanks for your response, appreciate your time. We want this application to only run on the two nodes (16 CPU and 120 GB memory each). I can’t understand why the scheduler keeps assigning pods to one of the nodes which is over 80% memory while the other node is only 40% used Is there a possibilty that despite the node affinity/tolleration, the scheduler is still calculating a score based on the overall cluster (8 nodes) ?
If I create a custom scheduler, do you know if it’s possible to isolate it to two nodes ? I’ve been scouring the internet but can’t find a way to do this. It might be easier to control the pods if the scheduler isn’t aware of the whole cluster to begin with ?
The scheduler is reliant in addition to tolerations a node selection(including affinity) to cpu and memory request.
It does not balance the load based on consumption but based on the cpu and memory request
My guess is that the 100millicore request is able to deploy on that node regardless to its current usage (which the scheduler does know about).
The way to inform the scheduler about an application consumption is using requests, i think profiling these applications properly will solve your issue
Sorry but I don’t understand how you mean it balances on request not consumption. Are you saying it combines the request total of each pod on each of the nodes and the node with the smallest total CPU & Request will be chosen ?
If we take a simple example of 2 statefulsets with 2 replicas with 5CPU/5GB memory
There are two worker nodes with 20CPU/20GB memory. If node A is 80% memory used and node B is 20% used and an additional stateful set with 2CPU/2GB , how is the scheduler going to decide which node to place this new application?
The scheduler nominates Pod (regardless if it is a statefulset, deployment or cronjob) by the amount of cpu and memory requested on that node. usage is not relevant to the scheduler.
as per the example you gave, you have a node with 20 cores and 20GB or ram allocateable (regardless to node capacity i.e. if you have system reserved or kubelet reserved the allocateable amount will be lower than the capacity. if a Pod has a request of 5 cores and 5GB of RAM the scheduler will nominate Pods to nodes which have an available request on them (CPU and memory) of at least 5 cores and 5GB or memory (regardless to actual usage on that node).
you can check requests on a node by describing a node (run kubectl describe node <nodename>:
(Total limits may be over 100 percent, i.e., overcommitted.)
Resource Requests Limits
-------- -------- ------
cpu 3822m (47%) 4874m (60%)
memory 2560Mi (10%) 5404Mi (22%)
ephemeral-storage 0 (0%) 0 (0%)
hugepages-2Mi 0 (0%) 0 (0%)
in the above example you can see that CPU requests are at 47%, even if actual consumption or usage on that node is 100% the scheduler will still be able to nominate and deploy a Pod with a 100 millicore CPU request on that node. The Pod might then be throttling if actual CPU usage is too high on that node but that does not matter to the sceduler.
my advise is to perform application profiling to your Pods (dynamically for each version) and make sure you set the proper requests (and limits) for each Pod.
I would love to have a chat about this if you wish, email me.
Thanks, so you mean it basically checks the total requests being used by the pods on each node (kubectl describe node ) and will send the pod to the one which has the lowest request limit regardless of how much memory is being used ?
Thanks, thought the scheduler was more intuative than that
Pedantically, it’s not always the node which has the lowest total requests. It looks at the total requests of all pods currently scheduled on a given node and other factors and makes a decision. Requests are considered, limits and “actual usage” are not.