简体   繁体   English

Kubernetes 中的资源分配:Pod 是如何调度的?

[英]Resource Allocation in Kubernetes: How are pods scheduled?

In Kubernetes, the role of the scheduler is to seek a suitable node for the pods.在 Kubernetes 中,调度程序的作用是为 Pod 寻找合适的节点。 So, after assigning a pod into a node, there are different pods on that node so that those pods are competing to gain resources.因此,在将 pod 分配到节点后,该节点上会有不同的 pod,以便这些 pod 竞争获取资源。 Therefore, for this competitive situation, how Kubernetes allocates resource?因此,对于这种竞争情况,Kubernetes 是如何分配资源的? Is there any source code in Kubernetes for computing resource allocation? Kubernetes 中是否有计算资源分配的源代码?

I suppose you can take a look at the below articles to see if that answers your query我想你可以看看下面的文章,看看是否能回答你的问题

https://github.com/kubernetes/community/blob/master/contributors/devel/sig-scheduling/scheduler_algorithm.md#ranking-the-nodes https://github.com/kubernetes/community/blob/master/contributors/devel/sig-scheduling/scheduler_algorithm.md#ranking-the-nodes

https://jvns.ca/blog/2017/07/27/how-does-the-kubernetes-scheduler-work/ https://jvns.ca/blog/2017/07/27/how-does-the-kubernetes-scheduler-work/

The filtered nodes are considered suitable to host the Pod, and it is often that there are more than one nodes remaining.过滤后的节点被认为适合托管 Pod,并且通常剩余的节点不止一个。 Kubernetes prioritizes the remaining nodes to find the "best" one for the Pod. Kubernetes 优先考虑剩余节点,为 Pod 找到“最佳”节点。 The prioritization is performed by a set of priority functions.优先级排序由一组优先级函数执行。 For each remaining node, a priority function gives a score which scales from 0-10 with 10 representing for "most preferred" and 0 for "least preferred".对于每个剩余的节点,优先级函数给出一个从 0 到 10 的分数,其中 10 代表“最喜欢”,0 代表“最不喜欢”。 Each priority function is weighted by a positive number and the final score of each node is calculated by adding up all the weighted scores.每个优先级函数都用一个正数加权,每个节点的最终分数是通过将所有加权分数相加来计算的。 For example, suppose there are two priority functions, priorityFunc1 and priorityFunc2 with weighting factors weight1 and weight2 respectively, the final score of some NodeA is:例如,假设有两个优先级函数,priorityFunc1和priorityFunc2,权重因子分别为weight1和weight2,某个NodeA的最终得分为:

finalScoreNodeA = (weight1 * priorityFunc1) + (weight2 * priorityFunc2)

After the scores of all nodes are calculated, the node with highest score is chosen as the host of the Pod.计算所有节点的得分后,选择得分最高的节点作为 Pod 的主机。 If there are more than one nodes with equal highest scores, a random one among them is chosen.如果有多个节点的最高分相同,则从其中随机选择一个。

Currently, Kubernetes scheduler provides some practical priority functions, including:目前,Kubernetes scheduler 提供了一些实用的优先级功能,包括:

LeastRequestedPriority : The node is prioritized based on the fraction of the node that would be free if the new Pod were scheduled onto the node. LeastRequestedPriority :如果新 Pod 被调度到节点上,则该节点根据空闲节点的比例进行优先级排序。 (In other words, (capacity - sum of requests of all Pods already on the node - request of Pod that is being scheduled) / capacity). (换句话说,(容量 - 节点上所有 Pod 的请求总和 - 正在调度的 Pod 的请求)/容量)。 CPU and memory are equally weighted. CPU 和内存的权重相同。 The node with the highest free fraction is the most preferred.具有最高游离分数的节点是最优选的。 Note that this priority function has the effect of spreading Pods across the nodes with respect to resource consumption.请注意,此优先级函数具有在资源消耗方面跨节点传播 Pod 的效果。

CalculateNodeLabelPriority : Prefer nodes that have the specified label. CalculateNodeLabelPriority :首选具有指定标签的节点。

BalancedResourceAllocation : This priority function tries to put the Pod on a node such that the CPU and Memory utilization rate is balanced after the Pod is deployed. BalancedResourceAllocation :这个优先级函数尝试将 Pod 放在一个节点上,以便在部署 Pod 后平衡 CPU 和内存利用率。

CalculateSpreadPriority : Spread Pods by minimizing the number of Pods belonging to the same service on the same node. CalculateSpreadPriority :通过最小化同一节点上属于同一服务的 Pod 数量来传播 Pod。 If zone information is present on the nodes, the priority will be adjusted so that pods are spread across zones and nodes.如果节点上存在区域信息,则会调整优先级,以便 pod 分布在区域和节点之间。

CalculateAntiAffinityPriority : Spread Pods by minimizing the number of Pods belonging to the same service on nodes with the same value for a particular label. CalculateAntiAffinityPriority :通过最小化节点上具有相同特定标签值的同一服务的 Pod 数量来传播 Pod。

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

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