首页 > 解决方案 > 无论稳定窗口如何,Kubernetes HPA 都在摆动副本

问题描述

根据 K8s文档stabilizationWindowSeconds,可以使用副本属性来避免抖动

当用于缩放的指标不断波动时,稳定窗口用于限制副本的摆动。自动缩放算法使用稳定窗口来考虑过去计算的期望状态以防止缩放。

当指标表明目标应该按比例缩小时,算法会查看先前计算的所需状态并使用指定间隔中的最大值。

根据我从文档中了解到的情况,使用以下 hpa 配置:

  horizontalPodAutoscaler:
    enabled: true
    minReplicas: 2
    maxReplicas: 14
    targetCPUUtilizationPercentage: 70
    behavior:
      scaleDown:
        stabilizationWindowSeconds: 1800
        policies:
          - type: Pods
            value: 1
            periodSeconds: 300
      scaleUp:
        stabilizationWindowSeconds: 60
        policies:
          - type: Pods
            value: 2
            periodSeconds: 60

如果在最后 1800 秒(30 分钟)内的任何时间 hpa 计算的目标 pod 数量等于 7 个 pod,则不应缩小我的部署(假设从 7 个 pod 到 6 个)。但我仍在观察部署中副本的抖动。

部署副本

我在文档中误解了什么以及如何避免连续扩大/缩小 1 个 pod?

Kubernetes v1.20

HPA 说明:

CreationTimestamp:                                     Thu, 14 Oct 2021 12:14:37 +0200
Reference:                                             Deployment/my-deployment
Metrics:                                               ( current / target )
  resource cpu on pods  (as a percentage of request):  64% (1621m) / 70%
Min replicas:                                          2
Max replicas:                                          14
Behavior:
  Scale Up:
    Stabilization Window: 60 seconds
    Select Policy: Max
    Policies:
      - Type: Pods  Value: 2  Period: 60 seconds
  Scale Down:
    Stabilization Window: 1800 seconds
    Select Policy: Max
    Policies:
      - Type: Pods  Value: 1  Period: 300 seconds
Deployment pods:    3 current / 3 desired
Conditions:
  Type            Status  Reason              Message
  ----            ------  ------              -------
  AbleToScale     True    ReadyForNewScale    recommended size matches current size
  ScalingActive   True    ValidMetricFound    the HPA was able to successfully calculate a replica count from cpu resource utilization (percentage of request)
  ScalingLimited  False   DesiredWithinRange  the desired count is within the acceptable range
Events:           <none>

标签: kubernetesautoscalinghpa

解决方案


v1.20 中的 k8s HPA 存在错误,请检查问题。升级到 v1.21 解决了该问题,升级后部署可扩展而不会抖动。

关于 2 天内部署的图片缩放:

部署规模超过 2 天


推荐阅读