@@ -68,7 +68,7 @@ The horizontal pod autoscaling controller, running within the Kubernetes
68
68
{{< glossary_tooltip text="control plane" term_id="control-plane" >}}, periodically adjusts the
69
69
desired scale of its target (for example, a Deployment) to match observed metrics such as average
70
70
CPU utilization, average memory utilization, or any other custom metric you specify.
71
- -->
71
+ -->
72
72
HorizontalPodAutoscaler 被实现为 Kubernetes API
73
73
资源和{{< glossary_tooltip text="控制器" term_id="controller" >}}。
74
74
@@ -404,8 +404,9 @@ HorizontalPodAutoscaler(HPA)控制器有两个标志会影响 Pod 启动期
404
404
1 . ` --horizontal-pod-autoscaler-cpu-initialization-period ` (默认:5 分钟)
405
405
406
406
此标志所定义的是 Pod 启动后的一个时间窗口,在此期间内其 ** CPU 使用率被忽略** ,除非:
407
- - Pod 处于 ` Ready ` 状态** 且**
408
- - 指标样本完全是在它处于 ` Ready ` 状态期间采集的。
407
+
408
+ - Pod 处于 ` Ready ` 状态** 且**
409
+ - 指标样本完全是在它处于 ` Ready ` 状态期间采集的。
409
410
410
411
<!--
411
412
This flag helps **exclude misleading high CPU usage** from initializing Pods (e.g., Java apps warming up) in HPA scaling decisions.
@@ -429,7 +430,9 @@ HorizontalPodAutoscaler(HPA)控制器有两个标志会影响 Pod 启动期
429
430
- Avoid including Pods that rapidly fluctuate between `Ready` and `Unready` during startup.
430
431
- Ensure stability in the initial readiness signal before HPA considers their metrics valid.
431
432
-->
433
+
432
434
其设计目的是:
435
+
433
436
- 避免包含在启动期间快速在 ` Ready ` 和 ` Unready ` 之间波动的 Pod。
434
437
- 确保在 HPA 认为它们的指标有效之前,初始就绪信号的稳定性。
435
438
@@ -447,22 +450,22 @@ HorizontalPodAutoscaler(HPA)控制器有两个标志会影响 Pod 启动期
447
450
448
451
<!--
449
452
#### Best Practice:
450
- If your Pod has a startup phase with high CPU usage, configure both:
451
- - `--horizontal-pod-autoscaler-cpu-initialization-period` to **cover the startup duration**.
452
- - Ensure your **readinessProbe** only reports `Ready` **after the CPU spike subsides**, using `initialDelaySeconds`.
453
+
454
+ If your Pod has a startup phase with high CPU usage:
455
+
456
+ - Configure a `startupProbe` that doesn't pass until the high CPU usage has passed, or
457
+ - Ensure your `readinessProbe` only reports `Ready` **after** the CPU spike subsides, using `initialDelaySeconds`.
458
+
459
+ And ideally also set `--horizontal-pod-autoscaler-cpu-initialization-period` to **cover the startup duration**.
453
460
-->
454
461
#### 最佳实践
455
462
456
- 如果你的 Pod 有一个 CPU 使用率较高的启动阶段,可以配置以下两项 :
463
+ 如果你的 Pod 有一个 CPU 使用率较高的启动阶段:
457
464
458
- - ` --horizontal-pod-autoscaler-cpu-initialization-period `
459
- 以** 覆盖启动持续时间** 。
460
- - 通过使用 ` initialDelaySeconds ` ,确保你的 ** readinessProbe** 在 CPU 峰值消退后才报告 ` Ready ` 。
465
+ - 配置 ` startupProbe ` ,使其在高 CPU 使用率结束之前不会传递,或
466
+ - 使用 ` initialDelaySeconds ` ,确保你的 ` readinessProbe ` ** 在 CPU 峰值过后** 才报告为 ` Ready ` 。
461
467
462
- <!--
463
- This avoids scaling based on temporary spikes that do not reflect long-term workload needs.
464
- -->
465
- 这样做可以避免基于临时峰值的缩放动作,这些峰值不反映长时间工作负载需求。
468
+ 理想情况下,还应设置 ` --horizontal-pod-autoscaler-cpu-initialization-period ` ,以** 覆盖启动持续时间** 。
466
469
467
470
<!--
468
471
## API Object
@@ -654,9 +657,12 @@ the old container name from the HPA specification.
654
657
655
658
<!--
656
659
# # Scaling on custom metrics
660
+ -->
661
+ # # 扩展自定义指标 {#scaling-on-custom-metrics}
657
662
658
663
{{< feature-state for_k8s_version="v1.23" state="stable" >}}
659
664
665
+ <!--
660
666
(the `autoscaling/v2beta2` API version previously provided this ability as a beta feature)
661
667
662
668
Provided that you use the `autoscaling/v2` API version, you can configure a HorizontalPodAutoscaler
@@ -666,10 +672,6 @@ API.
666
672
667
673
See [Support for metrics APIs](#support-for-metrics-apis) for the requirements.
668
674
-->
669
- # # 扩展自定义指标 {#scaling-on-custom-metrics}
670
-
671
- {{< feature-state for_k8s_version="v1.23" state="stable" >}}
672
-
673
675
(之前的 `autoscaling/v2beta2` API 版本将此功能作为 Beta 功能提供)
674
676
675
677
如果你使用 `autoscaling/v2` API 版本,则可以将 HorizontalPodAutoscaler
@@ -680,9 +682,12 @@ HorizontalPodAutoscaler 控制器能够从 Kubernetes API 查询这些自定义
680
682
681
683
<!--
682
684
# # Scaling on multiple metrics
685
+ -->
686
+ # # 基于多个指标来执行扩缩 {#scaling-on-multiple-metrics}
683
687
684
688
{{< feature-state for_k8s_version="v1.23" state="stable" >}}
685
689
690
+ <!--
686
691
(the `autoscaling/v2beta2` API version previously provided this ability as a beta feature)
687
692
688
693
Provided that you use the `autoscaling/v2` API version, you can specify multiple metrics for a
@@ -691,10 +696,6 @@ and proposes a new scale based on that metric. The HorizontalPodAutoscaler takes
691
696
recommended for each metric and sets the workload to that size (provided that this isn't larger than the
692
697
overall maximum that you configured).
693
698
-->
694
- # # 基于多个指标来执行扩缩 {#scaling-on-multiple-metrics}
695
-
696
- {{< feature-state for_k8s_version="v1.23" state="stable" >}}
697
-
698
699
(之前的 `autoscaling/v2beta2` API 版本将此功能作为 Beta 功能提供)
699
700
700
701
如果你使用 `autoscaling/v2` API 版本,你可以为 HorizontalPodAutoscaler 指定多个指标以进行扩缩。
@@ -766,9 +767,12 @@ and [the walkthrough for using external metrics](/docs/tasks/run-application/hor
766
767
767
768
<!--
768
769
# # Configurable scaling behavior
770
+ -->
771
+ # # 可配置的扩缩行为 {#configurable-scaling-behavior}
769
772
770
773
{{< feature-state for_k8s_version="v1.23" state="stable" >}}
771
774
775
+ <!--
772
776
(the `autoscaling/v2beta2` API version previously provided this ability as a beta feature)
773
777
774
778
If you use the `v2` HorizontalPodAutoscaler API, you can use the `behavior` field
@@ -777,10 +781,6 @@ to configure separate scale-up and scale-down behaviors.
777
781
You specify these behaviours by setting `scaleUp` and / or `scaleDown`
778
782
under the `behavior` field.
779
783
-->
780
- # # 可配置的扩缩行为 {#configurable-scaling-behavior}
781
-
782
- {{< feature-state for_k8s_version="v1.23" state="stable" >}}
783
-
784
784
(之前的 `autoscaling/v2beta2` API 版本将此功能作为 Beta 功能提供)
785
785
786
786
如果你使用 `v2` HorizontalPodAutoscaler API,你可以使用 `behavior` 字段
@@ -950,10 +950,8 @@ match the existing behavior in the HPA algorithm.
950
950
-->
951
951
# ## 默认行为 {#default-behavior}
952
952
953
- 要使用自定义扩缩,不必指定所有字段。
954
- 只有需要自定义的字段才需要指定。
955
- 这些自定义值与默认值合并。
956
- 默认值与 HPA 算法中的现有行为匹配。
953
+ 要使用自定义扩缩,不必指定所有字段。只有需要自定义的字段才需要指定。
954
+ 这些自定义值与默认值合并。默认值与 HPA 算法中的现有行为匹配。
957
955
958
956
` ` ` yaml
959
957
behavior:
@@ -984,8 +982,8 @@ For scaling up there is no stabilization window. When the metrics indicate that
984
982
scaled up the target is scaled up immediately. There are 2 policies where 4 pods or a 100% of the currently
985
983
running replicas may at most be added every 15 seconds till the HPA reaches its steady state.
986
984
-->
987
- 用于缩小稳定窗口的时间为 **300** 秒(或是 `--horizontal-pod-autoscaler-downscale-stabilization`
988
- 参数设定值)。
985
+ 用于缩小稳定窗口的时间为 **300**
986
+ 秒(或是 `--horizontal-pod-autoscaler-downscale-stabilization` 参数设定值)。
989
987
只有一种缩容的策略,允许 100% 删除当前运行的副本,这意味着扩缩目标可以缩小到允许的最小副本数。
990
988
对于扩容,没有稳定窗口。当指标显示目标应该扩容时,目标会立即扩容。
991
989
这里有两种策略,每 15 秒最多添加 4 个 Pod 或 100% 当前运行的副本数,直到 HPA 达到稳定状态。
@@ -1052,7 +1050,6 @@ behavior:
1052
1050
The `selectPolicy` value of `Disabled` turns off scaling the given direction.
1053
1051
So to prevent downscaling the following policy would be used :
1054
1052
-->
1055
-
1056
1053
# ## 示例:禁用缩容 {#example-disable-scale-down}
1057
1054
1058
1055
` selectPolicy` 的值 `Disabled` 会关闭对给定方向的缩容。
@@ -1117,7 +1114,6 @@ deployment.yaml`, this will instruct Kubernetes to scale the current number of P
1117
1114
to the value of the `spec.replicas` key. This may not be
1118
1115
desired and could be troublesome when an HPA is active, resulting in thrashing or flapping behavior.
1119
1116
-->
1120
-
1121
1117
# ## 将 Deployment 和 StatefulSet 迁移到水平自动扩缩 {#migrating-deployments-and-statefulsets-to-horizontal-autoscaling}
1122
1118
1123
1119
当启用 HPA 时,建议从它们的{{< glossary_tooltip text="清单" term_id="manifest" >}}中删除
@@ -1136,7 +1132,7 @@ update configuration as desired. You can avoid this degradation by choosing one
1136
1132
methods based on how you are modifying your deployments :
1137
1133
-->
1138
1134
请记住,删除 `spec.replicas` 可能会导致 Pod 计数一次性降级,因为此键的默认值为 1
1139
- (参考 [Deployment Replicas ](/zh-cn/docs/concepts/workloads/controllers/deployment#replicas))。
1135
+ (参考 [Deployment 副本 ](/zh-cn/docs/concepts/workloads/controllers/deployment#replicas))。
1140
1136
更新后,除 1 之外的所有 Pod 都将开始其终止程序。之后的任何部署应用程序都将正常运行,
1141
1137
并根据需要遵守滚动更新配置。你可以根据修改部署的方式选择以下两种方法之一来避免这种降级:
1142
1138
0 commit comments