Kubernetes Pod在优先模式下的节点间分布 [英] Kubernetes pod distribution amongst nodes with preferred mode

查看:485
本文介绍了Kubernetes Pod在优先模式下的节点间分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的应用程序迁移到Kubernetes.我正在使用EKS.

I am working on migrating my applications to Kubernetes. I am using EKS.

我想将Pod分配到不同的节点,以避免出现单点故障. 我读到有关pod-affinityanti-affinity以及requiredpreferred模式的信息.

I want to distribute my pods to different nodes, to avoid having a single point of failure. I read about pod-affinity and anti-affinity and required and preferred mode.

此答案提供了一种非常好的方法来完成此任务.

This answer gives a very nice way to accomplish this.

但是我的疑问是,如果我有3个节点,其中2个节点已满(在资源方面).如果使用requiredDuringSchedulingIgnoredDuringExecution,则k8s将启动新节点,并将吊舱分配到每个节点.如果使用preferredDuringSchedulingIgnoredDuringExecution,它将检查首选节点,而不是查找其他节点,只会将所有Pod部署在第三个节点上.在这种情况下,它将再次成为单点故障.

But my doubt is, let's say if I have 3 nodes, of which 2 are already full(resource-wise). If I use requiredDuringSchedulingIgnoredDuringExecution, k8s will spin-up new nodes and will distribute the pods to each node. And if I use preferredDuringSchedulingIgnoredDuringExecution, it will check for preferred-nodes, and not finding different nodes, will deploy all pods on the third node only. In which case, it will again become a single point of failure.

我该如何解决这个问题?

How do I solve this condition?

我能想到的一种方法是拥有一个过度配置的集群,这样总会有一些额外的节点.

One way I can think of is to have an over-provisioned cluster, so that there are always some extra nodes.

第二种方式,我不确定如何执行此操作,但是我认为应该有一种同时使用requiredDuringSchedulingIgnoredDuringExecutionpreferredDuringSchedulingIgnoredDuringExecution的方式.

Second way, I am not sure how to do this, but I think there should be a way of using both requiredDuringSchedulingIgnoredDuringExecution and preferredDuringSchedulingIgnoredDuringExecution.

有人可以帮我吗?我想念什么吗?人们在这种情况下如何工作?

Can anyone help me with this? Am I missing something? How do people work with this condition?

我是Kubernetes的新手,所以如果我错了或遗漏了一些东西,请随时纠正我.

I am new to Kubernetes, so feel free to correct me if I am wrong or missing something.

预先感谢

注意:

在同一节点上运行几个类似的Pod时我没有问题,只是不希望所有Pod在同一节点上运行,只是因为只有一个节点可供部署.

I don't have a problem running a few similar pods on the same node, just don't want all pods to be running on the same node, just because there was only one node available to deploy.

推荐答案

我看到您正在尝试确保k8永远不会在同一节点上调度所有pod副本.

I see you are trying to make sure that k8s will never schedule all pod replicas on the same node.

不可能为kubernetes调度程序创建像这样的硬需求.

It's not possible to create hard requrement like this for kubernetes scheduler.

Scheduler会尽最大努力尽可能均匀地调度您的应用程序,但是在您有2个没有备用资源的节点和1个将调度所有Pod副本的节点的情况下,k8可以执行以下操作之一(取决于配置) ):

Scheduler will try its best to schedule your application as evenly as possible but in situation when you have 2 nodes without spare resources and 1 node where all pod replicas would be scheduled, k8s can do one of the folowing actions (depending on configuration):

  1. 将Pod安排在一个节点上(尽力而为/默认)
  2. 只运行一个Pod,完全不计划其余的Pod(antiaffnity + requiredDuringSchedulingIgnoredDuringExecution)
  3. 根据需要为Pod创建新节点(antiaffnity + requiredDuringSchedulingIgnoredDuringExecution + cluster autoscaler)
  4. 开始从节点删除Pod,以释放高优先级Pod的资源( priority based preemption ),并在可能的情况下重新安排被抢占的广告连播
  1. schedule your pods on one node (best effort/default)
  2. run one pod and not schedule rest of the pods at all (antiaffnity + requiredDuringSchedulingIgnoredDuringExecution)
  3. create new nodes for pods if needed (antiaffnity + requiredDuringSchedulingIgnoredDuringExecution + cluster autoscaler)
  4. start deleting pods from nodes to free resources for high-priority pods (priority based preemption) and reschedule preempted pods if possible

也请阅读此

Also read this article to get better understanding on how scheduler makes its decisions.

您还可以使用 PodDisruptionBudget 告诉kubernetes进行确保指定的副本始终可以正常工作,但请记住,尽管:

You can also use PodDisruptionBudget to tell kubernetes to make sure a specified replicas are always working, remember that although:

中断预算并不能真正保证所指定豆荚的数量/百分比将一直保持不变.

A disruption budget does not truly guarantee that the specified number/percentage of pods will always be up.

kubernetes在制定调度决策时会考虑使用它.

kubernetes will take it under consideration when making scheduling decisions.

这篇关于Kubernetes Pod在优先模式下的节点间分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆