Skip to content

Commit ac3352b

Browse files
authored
Merge pull request #51400 from windsonsea/hpodsc
[zh] Sync horizontal-pod-autoscale.md
2 parents 1c7b875 + d67c93d commit ac3352b

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

content/zh-cn/docs/tasks/run-application/horizontal-pod-autoscale.md

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ The horizontal pod autoscaling controller, running within the Kubernetes
6868
{{< glossary_tooltip text="control plane" term_id="control-plane" >}}, periodically adjusts the
6969
desired scale of its target (for example, a Deployment) to match observed metrics such as average
7070
CPU utilization, average memory utilization, or any other custom metric you specify.
71-
-->
71+
-->
7272
HorizontalPodAutoscaler 被实现为 Kubernetes API
7373
资源和{{< glossary_tooltip text="控制器" term_id="controller" >}}。
7474

@@ -404,8 +404,9 @@ HorizontalPodAutoscaler(HPA)控制器有两个标志会影响 Pod 启动期
404404
1. `--horizontal-pod-autoscaler-cpu-initialization-period`(默认:5 分钟)
405405

406406
此标志所定义的是 Pod 启动后的一个时间窗口,在此期间内其 **CPU 使用率被忽略**,除非:
407-
- Pod 处于 `Ready` 状态****
408-
- 指标样本完全是在它处于 `Ready` 状态期间采集的。
407+
408+
- Pod 处于 `Ready` 状态****
409+
- 指标样本完全是在它处于 `Ready` 状态期间采集的。
409410

410411
<!--
411412
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 启动期
429430
- Avoid including Pods that rapidly fluctuate between `Ready` and `Unready` during startup.
430431
- Ensure stability in the initial readiness signal before HPA considers their metrics valid.
431432
-->
433+
432434
其设计目的是:
435+
433436
- 避免包含在启动期间快速在 `Ready``Unready` 之间波动的 Pod。
434437
- 确保在 HPA 认为它们的指标有效之前,初始就绪信号的稳定性。
435438

@@ -447,22 +450,22 @@ HorizontalPodAutoscaler(HPA)控制器有两个标志会影响 Pod 启动期
447450

448451
<!--
449452
#### 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**.
453460
-->
454461
#### 最佳实践
455462

456-
如果你的 Pod 有一个 CPU 使用率较高的启动阶段,可以配置以下两项
463+
如果你的 Pod 有一个 CPU 使用率较高的启动阶段:
457464

458-
- `--horizontal-pod-autoscaler-cpu-initialization-period`
459-
**覆盖启动持续时间**
460-
- 通过使用 `initialDelaySeconds`,确保你的 **readinessProbe** 在 CPU 峰值消退后才报告 `Ready`
465+
- 配置 `startupProbe`,使其在高 CPU 使用率结束之前不会传递,或
466+
- 使用 `initialDelaySeconds`,确保你的 `readinessProbe` **在 CPU 峰值过后**才报告为 `Ready`
461467

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`,以**覆盖启动持续时间**
466469

467470
<!--
468471
## API Object
@@ -654,9 +657,12 @@ the old container name from the HPA specification.
654657

655658
<!--
656659
## Scaling on custom metrics
660+
-->
661+
## 扩展自定义指标 {#scaling-on-custom-metrics}
657662

658663
{{< feature-state for_k8s_version="v1.23" state="stable" >}}
659664

665+
<!--
660666
(the `autoscaling/v2beta2` API version previously provided this ability as a beta feature)
661667

662668
Provided that you use the `autoscaling/v2` API version, you can configure a HorizontalPodAutoscaler
@@ -666,10 +672,6 @@ API.
666672

667673
See [Support for metrics APIs](#support-for-metrics-apis) for the requirements.
668674
-->
669-
## 扩展自定义指标 {#scaling-on-custom-metrics}
670-
671-
{{< feature-state for_k8s_version="v1.23" state="stable" >}}
672-
673675
(之前的 `autoscaling/v2beta2` API 版本将此功能作为 Beta 功能提供)
674676

675677
如果你使用 `autoscaling/v2` API 版本,则可以将 HorizontalPodAutoscaler
@@ -680,9 +682,12 @@ HorizontalPodAutoscaler 控制器能够从 Kubernetes API 查询这些自定义
680682

681683
<!--
682684
## Scaling on multiple metrics
685+
-->
686+
## 基于多个指标来执行扩缩 {#scaling-on-multiple-metrics}
683687

684688
{{< feature-state for_k8s_version="v1.23" state="stable" >}}
685689

690+
<!--
686691
(the `autoscaling/v2beta2` API version previously provided this ability as a beta feature)
687692

688693
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
691696
recommended for each metric and sets the workload to that size (provided that this isn't larger than the
692697
overall maximum that you configured).
693698
-->
694-
## 基于多个指标来执行扩缩 {#scaling-on-multiple-metrics}
695-
696-
{{< feature-state for_k8s_version="v1.23" state="stable" >}}
697-
698699
(之前的 `autoscaling/v2beta2` API 版本将此功能作为 Beta 功能提供)
699700

700701
如果你使用 `autoscaling/v2` API 版本,你可以为 HorizontalPodAutoscaler 指定多个指标以进行扩缩。
@@ -766,9 +767,12 @@ and [the walkthrough for using external metrics](/docs/tasks/run-application/hor
766767

767768
<!--
768769
## Configurable scaling behavior
770+
-->
771+
## 可配置的扩缩行为 {#configurable-scaling-behavior}
769772

770773
{{< feature-state for_k8s_version="v1.23" state="stable" >}}
771774

775+
<!--
772776
(the `autoscaling/v2beta2` API version previously provided this ability as a beta feature)
773777

774778
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.
777781
You specify these behaviours by setting `scaleUp` and / or `scaleDown`
778782
under the `behavior` field.
779783
-->
780-
## 可配置的扩缩行为 {#configurable-scaling-behavior}
781-
782-
{{< feature-state for_k8s_version="v1.23" state="stable" >}}
783-
784784
(之前的 `autoscaling/v2beta2` API 版本将此功能作为 Beta 功能提供)
785785

786786
如果你使用 `v2` HorizontalPodAutoscaler API,你可以使用 `behavior` 字段
@@ -950,10 +950,8 @@ match the existing behavior in the HPA algorithm.
950950
-->
951951
### 默认行为 {#default-behavior}
952952

953-
要使用自定义扩缩,不必指定所有字段。
954-
只有需要自定义的字段才需要指定。
955-
这些自定义值与默认值合并。
956-
默认值与 HPA 算法中的现有行为匹配。
953+
要使用自定义扩缩,不必指定所有字段。只有需要自定义的字段才需要指定。
954+
这些自定义值与默认值合并。默认值与 HPA 算法中的现有行为匹配。
957955

958956
```yaml
959957
behavior:
@@ -984,8 +982,8 @@ For scaling up there is no stabilization window. When the metrics indicate that
984982
scaled up the target is scaled up immediately. There are 2 policies where 4 pods or a 100% of the currently
985983
running replicas may at most be added every 15 seconds till the HPA reaches its steady state.
986984
-->
987-
用于缩小稳定窗口的时间为 **300** 秒(或是 `--horizontal-pod-autoscaler-downscale-stabilization`
988-
参数设定值)。
985+
用于缩小稳定窗口的时间为 **300**
986+
秒(或是 `--horizontal-pod-autoscaler-downscale-stabilization` 参数设定值)。
989987
只有一种缩容的策略,允许 100% 删除当前运行的副本,这意味着扩缩目标可以缩小到允许的最小副本数。
990988
对于扩容,没有稳定窗口。当指标显示目标应该扩容时,目标会立即扩容。
991989
这里有两种策略,每 15 秒最多添加 4 个 Pod 或 100% 当前运行的副本数,直到 HPA 达到稳定状态。
@@ -1052,7 +1050,6 @@ behavior:
10521050
The `selectPolicy` value of `Disabled` turns off scaling the given direction.
10531051
So to prevent downscaling the following policy would be used:
10541052
-->
1055-
10561053
### 示例:禁用缩容 {#example-disable-scale-down}
10571054

10581055
`selectPolicy` 的值 `Disabled` 会关闭对给定方向的缩容。
@@ -1117,7 +1114,6 @@ deployment.yaml`, this will instruct Kubernetes to scale the current number of P
11171114
to the value of the `spec.replicas` key. This may not be
11181115
desired and could be troublesome when an HPA is active, resulting in thrashing or flapping behavior.
11191116
-->
1120-
11211117
### 将 Deployment 和 StatefulSet 迁移到水平自动扩缩 {#migrating-deployments-and-statefulsets-to-horizontal-autoscaling}
11221118

11231119
当启用 HPA 时,建议从它们的{{< glossary_tooltip text="清单" term_id="manifest" >}}中删除
@@ -1136,7 +1132,7 @@ update configuration as desired. You can avoid this degradation by choosing one
11361132
methods based on how you are modifying your deployments:
11371133
-->
11381134
请记住,删除 `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))。
11401136
更新后,除 1 之外的所有 Pod 都将开始其终止程序。之后的任何部署应用程序都将正常运行,
11411137
并根据需要遵守滚动更新配置。你可以根据修改部署的方式选择以下两种方法之一来避免这种降级:
11421138

0 commit comments

Comments
 (0)