Kubernetes Autoscale 参数优化

271 阅读2分钟

调整Autoscale的参数,应该从应用程序的性质、负载类型、资源需求和预算限制等多个因素考虑。

  • 负载的稳定性:如果你的应用程序的负载稳定,并且在添加新的 Pod 后可以迅速响应并适应负载的增加,那么较短的延迟时间和持续时间可能是合理的。
  • Pod 的启动时间:如果你的应用程序的 Pod 启动时间相对较长,可能需要更长的延迟时间来确保新的 Pod 在稳定之前不会被缩容。
  • 缩容的频率:较短的延迟时间和持续时间可能导致频繁的缩容操作。

Kubernetes Autoscale 启动参数如下:

--scale-down-candidates-pool-min-count="50": Specifies the minimum number of pods in the candidate pool for scale-down evaluation.

--scale-down-candidates-pool-ratio="0.1": Sets the ratio of pods in the candidate pool to the total number of pods. If the number of pods in the candidate pool falls below this ratio, scale-down evaluation is triggered.

--scale-down-delay-after-add="10m0s": Defines the delay period after a pod is added before starting scale-down evaluation.

--scale-down-delay-after-delete="0s": Sets the delay period after a pod is deleted before starting scale-down evaluation.

--scale-down-delay-after-failure="3m0s": Specifies the delay period after a pod failure before starting scale-down evaluation.

--scale-down-enabled="true": Enables or disables the scale-down feature.

--scale-down-gpu-utilization-threshold="0.5": Sets the GPU utilization threshold for scale-down evaluation. If the GPU utilization of a pod falls below this threshold, it becomes a candidate for scale-down.

--scale-down-non-empty-candidates-count="30": Specifies the number of non-empty pods to consider in the candidate pool for scale-down evaluation.

--scale-down-simulation-timeout="5m0s": Sets the timeout duration for the scale-down simulation.

--scale-down-unneeded-time="1m0s": Defines the duration of time that a pod should be unneeded before it becomes a candidate for scale-down.

--scale-down-unready-time="20m0s": Specifies the duration of time that a pod can remain unready before it becomes a candidate for scale-down.

--scale-down-utilization-threshold="0.5": Sets the CPU utilization threshold for scale-down evaluation. If the CPU utilization of a pod falls below this threshold, it becomes a candidate for scale-down.

--scale-up-from-zero="true": Enables or disables the scale-up feature when there are no pods running.

--scan-interval="10s": Sets the interval at which the autoscaler scans and evaluates the pod scaling.

10分钟后释放一个节点

ip-10-0-74-59.us-east-2.compute.internal is unneeded since 2023-07-18 02:02:02.656762635 +0000 UTC m=+280607.679390031 duration 9m4.720551795s ip-10-0-74-59.us-east-2.compute.internal was unneeded for 9m4.720551795s
ip-10-0-74-59.us-east-2.compute.internal for removal
ip-10-0-74-59.us-east-2.compute.internal may be removed

为了能更有效的弹性申缩spot节点,重点修改三个参数:

--scale-down-utilization-threshold=0.1

节点的CPU利用率低于10%,触发缩容操作,从而快速释放资源

--scale-down-delay-after-add=30s

Node节点在 30 秒内不会触发缩容操作

--scale-down-unneeded-time=2m

Node节点在 2 分钟内不再被需要时,会成为缩容的候选对象。