问题描述
我们可以使用DaemonSet对象在每个节点上部署一个副本.我们如何在每个节点上部署2个副本或3个副本?我们如何实现这一目标.请让我们知道
We can use DaemonSet object to deploy one replica on each node. How can we deploy say 2 replicas or 3 replicas per node? How can we achieve that. please let us know
推荐答案
无法像Daemonset那样在每个节点上强制x个pod.但是,通过一些计划,您可以使用 pod反亲和力.
There is no way to force x pods per node the way a Daemonset does. However, with some planning, you can force a fairly even pod distribution across your nodes using pod anti affinity.
假设我们有10个节点.首先,我们需要具有30个Pod(每个节点3个)的ReplicaSet(部署).接下来,我们要设置Pod反关联性,以使用权重较高的preferredDuringSchedulingIgnoredDuringExecution
并匹配部署的标签.这将导致调度程序宁愿不调度已存在相同容器的容器.一旦每个节点有1个容器,该循环将重新开始.具有2个容器的节点的权重将低于具有1个容器的节点的权重,因此下一个容器应尝试去那里.
Let's say we have 10 nodes. The first thing is we need to have a ReplicaSet (deployment) with 30 pods (3 per node). Next, we want to set the pod anti affinity to use preferredDuringSchedulingIgnoredDuringExecution
with a relatively high weight and match the deployment's labels. This will cause the scheduler to prefer not scheduling pods where the same pod already exists. Once there is 1 pod per node, the cycle starts over again. A node with 2 pods will be weighted lower than one with 1 pod so the next pod should try to go there.
请注意,这不如DaemonSet精确,并且在扩展或缩小集群时可能会遇到一些限制.
Note this is not as precise as a DaemonSet and may run into some limitations when it comes time to scale up or down the cluster.
扩展群集的一种更可靠的方法是简单地创建多个具有不同名称但彼此相同的DaemonSet.由于DaemonSet将具有相同的标签,因此它们都可以通过相同的服务公开.
A more reliable way if scaling the cluster is to simply create multiple DaemonSets with different names, but identical in every other way. Since the DaemonSets will have the same labels, they can all be exposed through the same service.
这篇关于Kubernetes:将副本均匀分布在整个集群中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!