HPA的Kubernetes Pod CPU使用率计算方法 [英] Kubernetes pod cpu usage calculation method for HPA

查看:592
本文介绍了HPA的Kubernetes Pod CPU使用率计算方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释如何在具有多个容器的吊舱内与水平吊舱自动缩放器一起使用时计算cpu使用率吗? 是平均值吗?如何计算?

Can someone explain how the cpu usage is calculated inside pods with multiple containers for use with an Horizontal Pod Autoscaler? Is it the mean value and how is this calculated?

例如: 如果我们有2个容器:

For example: If we have 2 containers:

  • Container1请求0.5 cpu并使用0 cpu
  • Container2请求1 cpu并使用2 cpu

如果我们分别计算两者并取平均值:(0%+ 200%)/2 = 100%使用率?

If we calculate both seperatly and take the mean: (0% + 200%)/2 = 100% usage?

如果我们求和并取平均值:2/1.5 = 133%使用率?

If we take the sums and take the mean: 2/1.5 = 133% usage?

或者我的逻辑方式是否可行?

Or is my logic way off?

推荐答案

从kubernetes 1.9开始,HPA将pod cpu利用率计算为pod中所有容器的总cpu使用率除以总请求数.因此,在您的示例中,计算出的使用量将为133%.我认为文档的任何地方都没有指定,但是相关代码在这里:

As of kubernetes 1.9 HPA calculates pod cpu utilization as total cpu usage of all containers in pod divided by total request. So in your example the calculated usage would be 133%. I don't think that's specified in docs anywhere, but the relevant code is here: https://github.com/kubernetes/kubernetes/blob/v1.9.0/pkg/controller/podautoscaler/metrics/utilization.go#L49

但是,我认为这是一个实现细节.因此,它可以在将来的版本中轻松更改.

However, I would consider this an implementation detail. As such it can easily change in future versions.

这篇关于HPA的Kubernetes Pod CPU使用率计算方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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