I'm trying to find out how kubernetes calculates the allocation of resources? Actually, I cannot find it in the source code. In kubernetes official documentation, allocatable has been calculated as [Allocatable] = [Node Capacity] - [Kube-Reserved] - [System-Reserved] - [Hard-Eviction-Threshold]. Could you please help me to find the related source codes in kubernetes which is in github?
Actually, I would like to change the allocation policy in kubernetes and I need to find the related codes.
Cheers
There are a couple of options:
The scheduler uses the value of node.Status.Allocatable instead of node.Status.Capacity to decide if a node will become a candidate for pod scheduling. So one thing is to do custom stuff , is to bypass the schedular and specify your own schedular.
The second option is to change the values and options used by kubelet. details
You can set these in the kubeletArguments section of the node configuration map by using a set of = pairs (e.g., cpu=200m,memory=512Mi). Add the section if it does not already exist
start from here:
// AllocatableResource returns allocatable resources on a given node.
func (n *NodeInfo) AllocatableResource() Resource {
if n == nil {
return emptyResource
}
return *n.allocatableResource
}
here is a portion of schedular that uses that info:
if allocatable.Memory < podRequest.Memory+nodeInfo.RequestedResource().Memory {
predicateFails = append(predicateFails, NewInsufficientResourceError(v1.ResourceMemory, podRequest.Memory, nodeInfo.RequestedResource().Memory, allocatable.Memory))
}