简体   繁体   English

有关Kubernetes中资源分配的问题

[英]A question regarding resource allocation in Kubernetes

I'm trying to find out how kubernetes calculates the allocation of resources? 我正在尝试找出kubernetes如何计算资源分配? 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]. 在kubernetes官方文档中,可分配的计算公式为[可分配的] = [节点容量]-[保留的Kube]-[保留的系统]-[硬逐出阈值]。 Could you please help me to find the related source codes in kubernetes which is in github? 您能帮我在github的kubernetes中找到相关的源代码吗?

Actually, I would like to change the allocation policy in kubernetes and I need to find the related codes. 实际上,我想更改kubernetes中的分配策略,并且需要找到相关代码。

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. 调度程序使用node.Status.Allocatable的值而不是node.Status.Capacity的值来确定节点是否将成为Pod调度的候选者。 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. 第二个选项是更改kubelet使用的值和选项。 details 细节

You can set these in the kubeletArguments section of the node configuration map by using a set of = pairs (eg, cpu=200m,memory=512Mi). 您可以使用一组=对(例如,cpu = 200m,内存= 512Mi)在节点配置图的kubeletArguments部分中进行设置。 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 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 https://github.com/kubernetes/kubernetes/blob/788f24583e95ac47938a41daaf1f1efc58153738/pkg/scheduler/algorithm/predicates/predicates.go

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM