简体   繁体   English

Kubernetes HPA 自动缩放速度

[英]Kubernetes HPA Auto Scaling Velocity

We have defined HPA for an application to have min 1 and max 4 replicas with 80% cpu as the threshold.我们为应用程序定义了 HPA,使其具有最小 1 个和最大 4 个副本,以 80% cpu 作为阈值。

What we wanted was, if the pod cpu goes beyond 80%, the app needs to be scaled up 1 at a time.我们想要的是,如果 pod cpu 超过 80%,应用程序需要一次扩展 1 个。 Instead what is happening is the application is getting scaled up to max number of replicas.相反,正在发生的事情是应用程序正在扩大到最大数量的副本。

How can we define the scale velocity to scale 1 pod at a time.我们如何定义一次缩放 1 个 pod 的缩放速度。 And again if one of the pod consumes more than 80% cpu then scale one more pod up but not maximum replicas.同样,如果其中一个 pod 消耗超过 80% 的 cpu,则再扩展一个 pod,但不是最大副本数。

Let me know how do we achieve this.让我知道我们如何实现这一目标。

First of all, the 80% CPU utilisation is not a threshold but a target value.首先,80% CPU 利用率不是阈值而是目标值。

The HPA algorithm for calculating the desired number of replicas is based on the following formula:计算所需副本数的HPA 算法基于以下公式:

X = N * (C/T)

Where:在哪里:

  • X : desired number of replicas X :所需的副本数
  • N : current number of replicas N : 当前副本数
  • C : current value of the metric C :公制的当前值
  • T : target value for the metric T :指标的目标值

In other words, the algorithm aims at calculating a replica count that keeps the observed metric value as close as possible to the target value.换句话说,该算法旨在计算使观察到的度量值尽可能接近目标值的副本计数。

In your case, this means if the average CPU utilisation across the pods of your app is below 80%, the HPA tends to decrease the number of replicas (to make the CPU utilisation of the remaining pods go up).在您的情况下,这意味着如果您的应用程序的 pod 的平均 CPU 利用率低于 80%,HPA 倾向于减少副本的数量(以使剩余 pod 的 CPU 利用率 go 上升)。 On the other hand, if the average CPU utilisation across the pods is above 80%, the HPA tends to increase the number of replicas, so that the CPU utilisation of the individual pods decreases.另一方面,如果跨 Pod 的平均 CPU 利用率在 80% 以上,HPA 倾向于增加副本数,从而降低单个 Pod 的 CPU 利用率。

The number of replicas that are added or removed in a single step depends on how far apart the current metric value is from the target value and on the current number of replicas.在单个步骤中添加或删除的副本数量取决于当前指标值与目标值的距离以及当前的副本数量。 This decision is internal to the HPA algorithm and you can't directly influence it.这个决定是 HPA 算法内部的,你不能直接影响它。 The only contract that the HPA has with its users is to keep the metric value as close as possible to the target value. HPA 与其用户的唯一合同是使度量值尽可能接近目标值。

If you need a very specific autoscaling behaviour, you can write a custom controller (or operator) to autoscale your application instead of using the HPA.如果您需要非常具体的自动缩放行为,您可以编写自定义 controller(或运算符)来自动缩放您的应用程序,而不是使用 HPA。

This - https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#algorithm-details - expains the algorithm HPA uses, including the formula to calculate the number of "desired replicas".这 - https://kubernetes.io/docs/tasks/run-application/horizontal -pod-autoscale/#algorithm-details - 解释了 HPA 使用的算法,包括计算“所需副本”数量的公式。

If I recall, there were some (positive) changes to the HPA algo with v1.12.如果我记得,v1.12 对 HPA 算法进行了一些(积极的)更改。

HPA has total control on scale up as of today.截至今天,HPA 完全控制了扩大规模。 You can only fine tune scale down operation with the following parameter.您只能使用以下参数微调按比例缩小操作。

--horizontal-pod-autoscaler-downscale-stabilization --horizontal-pod-autoscaler-downscale-stabilization

The good news is that there is a proposal for Configurable scale up/down velocity for HPA好消息是,有一个关于HPA 的可配置纵向扩展/缩减速度的提议

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM