在Kubernetes Horizo​​ntal Pod Autoscaler中如何缩小Pod副本的缩放比例? [英] How does pod replica scaling down work in Kubernetes Horizontal Pod Autoscaler?

查看:85
本文介绍了在Kubernetes Horizo​​ntal Pod Autoscaler中如何缩小Pod副本的缩放比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是,在Kubernetes中,当使用Horizo​​ntal Pod Autoscaler时,如果targetCPUUtilizationPercentage字段设置为50%,并且所有Pod副本中的平均CPU利用率高于该值,则HPA将创建更多副本.一旦一段时间平均CPU降到50%以下,它就会减少副本数.

以下是我不确定的部分:
如果Pod上的CPU利用率是10%而不是0%,HPA还会终止副本吗?
10%CPU并不多,但是由于它不是0%,因此当前正在运行某些任务那个豆荚.如果这是一项持续时间很长的任务(几秒钟),而HPA决定终止该Pod,则该任务将不会完成.

My understanding is that in Kubernetes, when using the Horizontal Pod Autoscaler, if the targetCPUUtilizationPercentage field is set to 50%, and the average CPU utilization across all the pod's replicas is above that value, the HPA will create more replicas. Once the average CPU drops below 50% for some time, it will lower the number of replicas.

Here is the part that I am not sure about:
What if the CPU utilization on a pod is 10%, not 0%?Will HPA still terminate the replica?
10% CPU isn't much, but since it's not 0%, some task is currently running on that pod. If it's a long lasting task (several seconds) and HPA decides to terminate the pod, that task will not be finished.

仅当它们上的CPU利用率为0%时,HPA才终止它们吗?或者,只要发现值低于targetCPUUtilizationPercentage,它就会终止它们吗?

Does the HPA terminate pods only if the CPU utilization on them is 0% or does it terminate them whenever it sees that the value is below targetCPUUtilizationPercentage?

HPA如何决定要删除的吊舱?
谢谢!

How does HPA decide which pods to remove?
Thank you!

推荐答案

所以您有两个问题,让我一个接一个地解决.第一部分-如果副本集中的Pod消耗了10%,那么Kubernetes会杀死该Pod吗?答案是肯定的. Kubernetes不会查看单个Pod,而是查看该副本集中所有Pod中该指标的平均值.同样,按比例缩小也是逐步如此处所述

So you have two questions in there and let me address one by one. The first part - if a pod in a replica set is consuming let's say 10% then will Kubernetes kill that pod? The answer is Yes. Kubernetes is not looking at the individual pods but at an average of that metric across all pods in that replica set. Also the scaling down is gradual as explained here

问题的第二部分-当Pod即将被杀死并且仍在处理某些请求时,您的应用程序如何正常运行?这可以通过吊舱终止的宽限期,如果您实现 a PreStop挂钩-这将使您可以停止接收传入的请求,而处理现有的请求.实现的方法会根据您所使用的语言运行时的不同而有所差异,因此在此不再赘述.

The second part of the question - how does your application behave gracefully when a pod is about to be killed and it is still serving some requests? This can be handled by the grace period of the pod termination and even better if you implement a PreStop hook - which will allow you to do something like stop taking incoming requests but process existing requests. The implementation of this will vary based on the language runtime you are using, so I won't go in the details here.

最后-您应该考虑的一种情况是,正在运行Pod的VM突然崩溃-您没有机会执行PreStop挂钩!我认为应用程序必须足够强大以处理故障.

Lastly - one scenario you should consider is what if VM on which pod was running goes down abruptly - you have no chance to execute PreStop hook! I think the application needs to be robust enough to handle failures.

这篇关于在Kubernetes Horizo​​ntal Pod Autoscaler中如何缩小Pod副本的缩放比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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