如何在不在集群中所有节点的子组上使用 daemonset 的情况下在每个节点上启动一个 pod?

How to launch one pod on each node without using daemonset on a subgroup of all nodes in a cluster?

假设我们有一个包含 10 个节点的集群,我们想在其中 3 个节点上启动应用程序的副本,该怎么做?

我考虑了一下,想出了以下解决方案,但每个都有问题:

这个问题的解决方案是什么?

Label those 3 nodes and use that label in the application with replicas=3 but we might end up with two replicas on one node (for High Availability I want to prevent this).

您可以使用 podAntiAffinity 规则或 topologySpreadConstraints 来避免 2 Pods 在同一个节点上开始

Label those 3 nodes and use daemonset and use that label in daemonset but then we will have 7 pods in pending mode.

如果您的 DeamonSet nodeSelector 匹配 3 个节点,调度程序将坚持这些节点。不应该 Pods 卡在待定状态。

两种解决方案听起来都不错。也许使用 Deployment + affinities 会更可靠:使用 DaemonSet,如果您的一个节点出现故障,则在您修复该节点之前不会重新安排第三个副本。这可能是问题,也可能不是问题……取决于您。