1

下午好。我正在使用 HPA (Horizo​​ntalPodAutoscaler) 自动缩放 Pod 的副本,在这种情况下,我使用内存使用作为参考,我声明如下:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: find-complementary-account-info-1
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: find-complementary-account-info-1
  minReplicas: 2
  maxReplicas: 5
  metrics:
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 70

我想要的是在 pod 的内存使用百分比大于 70% 时自动扩展我的 pod,并且当这个百分比下降时,我的副本返回到声明的最小值,但是,在进行测试时,我将限制设置为 70,但没有,当内存使用低于此值时,副本继续在 4。

5 分钟过去了,这就是 HPA 显示的内容:

[dockermd@tmp108 APP-MM-ConsultaCuentaPagadoraPospago]$ kubectl get hpa -o wide
NAME                                REFERENCE                                      TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
find-complementary-account-info-1   Deployment/find-complementary-account-info-1   65%/70%   2         5         4          2d4h

我对 HPA 有错误的概念,或者我以错误的方式声明了 HPA 的配置,或者当内存使用量低于指定值时如何减少副本数量

我的环境是本地的,并且配置了 metalb,我使用 LoadBalancer 来公开我的服务

4

1 回答 1

0

它按设计工作。该算法使用以下公式计算所需的副本数:

desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]

所以如果你desiredMetricValue是 70% 和currentMetricValue65% 比

desiredReplicas=4*(65%/70%)=~3.7

CEIL() 函数返回大于或等于数字的最小整数值,因此在本例中为 4。

如果要将数量减少到 3 个副本,则必须将利用率降低到 52.5%:

3=4*(`currentMetricValue`/70)
currentMetricValue=52.5%
于 2020-11-02T17:55:44.967 回答