A question regarding resource allocation in Kubernetes

3/23/2019

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

-- HamiBU
kubernetes

1 Answer

3/23/2019

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

  • Maybe the last option you are looking for is to change the code , the way things are calculated.

https://github.com/kubernetes/kubernetes/blob/05183bffe5cf690b418718aa107f5655e4ac0618/pkg/scheduler/nodeinfo/node_info.go

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))
    }

https://github.com/kubernetes/kubernetes/blob/788f24583e95ac47938a41daaf1f1efc58153738/pkg/scheduler/algorithm/predicates/predicates.go

-- Ijaz Ahmad Khan
Source: StackOverflow