Kubernetes 使用哪种算法将 pods 分配给节点?
Which algorithim does Kubernetes use to assign pods to nodes?
这更多的是成本估算问题,而不是如何使用节点亲和力等功能。
所以基本上 m
pods 有一些限制,例如:
- 特定
Deployments
/ StatefulSets
的每个 pod 应该在不同的 kubernetes 节点上
特定 Deployments
/ StatefulSets
的 - pods 应在 3 个可用性区域上平衡
现在,我想知道我需要多少个节点(所有相同类型)来托管给定的一组 Deployments
/ StatefulSets
。
我首先认为这更像是要使用匈牙利算法解决的分配问题,但这在多维约束等术语中似乎要复杂得多。
Kubernetes 根据
等许多约束分配 pods
- 资源需求
- 资源存在(节点容量)
- 节点选择器(如果有)或关联规则
- 相似性规则的权重
这篇文章同样适用于:https://kubernetes.io/docs/concepts/scheduling-eviction/kube-scheduler/
另外:https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/
我建议阅读:https://kubernetes.io/docs/concepts/scheduling-eviction/
据我所知,kube-scheduler 默认使用的算法在 github here.
中有描述
它解释了它是如何工作的。它首先过滤不符合pods要求的节点,例如资源请求 > 节点上的可用资源、亲和力等
然后使用排序算法来确定最合适的节点。如需更深入地了解
参考网友Harsh Manvar, I will add a few more information from myself. This topic was covered in the documentation, as described by my predecessor. Besides her, you can find very good materials here很好的回答:
What Happens When You Create a Pod On a Kubernetes Cluster?
In a matter of seconds, the Pod is up and running on one of the cluster nodes. However, a lot has happened within those seconds. Let’s see:
- While scanning the API server (which it is continuously doing), the Kubernetes Scheduler detects that there is a new Pod without a nodeName parameter. The nodeName is what shows which node should be owning this Pod.
- The Scheduler selects a suitable node for this Pod and updates the Pod definition with the node name (though the nodeName parameter).
- The kubelet on the chosen node is notified that there is a pod that is pending execution.
- The kubelet executes the Pod, and the latter starts running on the node.
您还可以找到有关调度进程和调度程序算法的 tutorial。
这更多的是成本估算问题,而不是如何使用节点亲和力等功能。
所以基本上 m
pods 有一些限制,例如:
- 特定
Deployments
/StatefulSets
的每个 pod 应该在不同的 kubernetes 节点上
特定 - pods 应在 3 个可用性区域上平衡
Deployments
/ StatefulSets
的 现在,我想知道我需要多少个节点(所有相同类型)来托管给定的一组 Deployments
/ StatefulSets
。
我首先认为这更像是要使用匈牙利算法解决的分配问题,但这在多维约束等术语中似乎要复杂得多。
Kubernetes 根据
等许多约束分配 pods- 资源需求
- 资源存在(节点容量)
- 节点选择器(如果有)或关联规则
- 相似性规则的权重
这篇文章同样适用于:https://kubernetes.io/docs/concepts/scheduling-eviction/kube-scheduler/
另外:https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/
我建议阅读:https://kubernetes.io/docs/concepts/scheduling-eviction/
据我所知,kube-scheduler 默认使用的算法在 github here.
中有描述它解释了它是如何工作的。它首先过滤不符合pods要求的节点,例如资源请求 > 节点上的可用资源、亲和力等
然后使用排序算法来确定最合适的节点。如需更深入地了解
参考网友Harsh Manvar, I will add a few more information from myself. This topic was covered in the documentation, as described by my predecessor. Besides her, you can find very good materials here很好的回答:
What Happens When You Create a Pod On a Kubernetes Cluster? In a matter of seconds, the Pod is up and running on one of the cluster nodes. However, a lot has happened within those seconds. Let’s see:
- While scanning the API server (which it is continuously doing), the Kubernetes Scheduler detects that there is a new Pod without a nodeName parameter. The nodeName is what shows which node should be owning this Pod.
- The Scheduler selects a suitable node for this Pod and updates the Pod definition with the node name (though the nodeName parameter).
- The kubelet on the chosen node is notified that there is a pod that is pending execution.
- The kubelet executes the Pod, and the latter starts running on the node.
您还可以找到有关调度进程和调度程序算法的 tutorial。