【问题标题】:Kubernetes HPA is flapping replicas regardless of stabilisation window无论稳定窗口如何,Kubernetes HPA 都在摆动副本
【发布时间】:2021-12-14 12:47:58
【问题描述】:

根据K8s documentation,可以使用stabilizationWindowSeconds避免replicas属性的抖动

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

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

根据我从文档中了解到的情况,使用以下 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>

【问题讨论】:

  • 您使用了哪个版本的 Kubernetes,您在集群中具体部署了什么?
  • @MikołajGłodziak K8s 版本是 1.20,部署是一个 Spring Boot 应用,服务于 rest api。
  • 您能分享您的部署和 HPA 配置 yaml 文件吗?你能粘贴kubectl describe hpa 命令的输出吗?您能否检查此部署中的所有 pod 是否都处于 Running 状态,并且没有任何 pod 以某种方式卡住(例如处于 Terminating 状态)?
  • 您是否尝试在较新的 Kubernetes 版本上运行您的部署 - v.1.20 仅支持一个月?
  • @MikolajS。我已在问题中添加了 hpa 描述。副本的抖动并不总是发生,很难在缩放之前捕捉到状态。在日志中看不到终止 Pod 并且没有错误,所以我相信这是因为自动缩放。在启用 HPA 之前没有重新启动 Pod。我没有尝试更新版本的 K8s,版本可能是一个原因。

标签: kubernetes autoscaling hpa


【解决方案1】:

k8s HPA v1.20 有一个bug,查看issue。升级到 v1.21 解决了这个问题,部署在升级后没有抖动。

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

【讨论】:

    猜你喜欢
    • 2021-01-20
    • 1970-01-01
    • 2022-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多