@@ -434,6 +434,127 @@ usual.
434
434
如果延迟(冷却)时间设置的太短,那么副本数量有可能跟以前一样出现抖动。
435
435
{{< /note >}}
436
436
437
+ <!--
438
+ ## Support for resource metrics
439
+
440
+ Any HPA target can be scaled based on the resource usage of the pods in the scaling target.
441
+ When defining the pod specification the resource requests like `cpu` and `memory` should
442
+ be specified. This is used to determine the resource utilization and used by the HPA controller
443
+ to scale the target up or down. To use resource utilization based scaling specify a metric source
444
+ like this:
445
+ -->
446
+ ## 对资源指标的支持 {#support-for-resource-metrics}
447
+
448
+ HPA 的任何目标资源都可以基于其中的 Pods 的资源用量来实现扩缩。
449
+ 在定义 Pod 规约时,类似 ` cpu ` 和 ` memory ` 这类资源请求必须被设定。
450
+ 这些设定值被用来确定资源利用量并被 HPA 控制器用来对目标资源完成扩缩操作。
451
+ 要使用基于资源利用率的扩缩,可以像下面这样指定一个指标源:
452
+
453
+ ``` yaml
454
+ type : Resource
455
+ resource :
456
+ name : cpu
457
+ target :
458
+ type : Utilization
459
+ averageUtilization : 60
460
+ ` ` `
461
+
462
+ <!--
463
+ With this metric the HPA controller will keep the average utilization of the pods in the scaling
464
+ target at 60%. Utilization is the ratio between the current usage of resource to the requested
465
+ resources of the pod. See [Algorithm](#algorithm-details) for more details about how the utilization
466
+ is calculated and averaged.
467
+ -->
468
+ 基于这一指标设定,HPA 控制器会维持扩缩目标中的 Pods 的平均资源利用率在 60%。
469
+ 利用率是 Pod 的当前资源用量与其请求值之间的比值。关于如何计算利用率以及如何计算平均值
470
+ 的细节可参考[算法](#algorithm-details)小节。
471
+
472
+ {{< note >}}
473
+ <!--
474
+ Since the resource usages of all the containers are summed up the total pod utilization may not
475
+ accurately represent the individual container resource usage. This could lead to situations where
476
+ a single container might be running with high usage and the HPA will not scale out because the overall
477
+ pod usage is still within acceptable limits.
478
+ -->
479
+ 由于所有的容器的资源用量都会被累加起来,Pod 的总体资源用量值可能不会精确体现
480
+ 各个容器的资源用量。这一现象也会导致一些问题,例如某个容器运行时的资源用量非常
481
+ 高,但因为 Pod 层面的资源用量总值让人在可接受的约束范围内,HPA 不会执行扩大
482
+ 目标对象规模的操作。
483
+ {{< /note >}}
484
+
485
+ <!--
486
+ ### Container Resource Metrics
487
+ -->
488
+ ### 容器资源指标 {#container-resource-metrics}
489
+
490
+ {{< feature-state for_k8s_version="v1.20" state="alpha" >}}
491
+
492
+ <!--
493
+ ` HorizontalPodAutoscaler` also supports a container metric source where the HPA can track the
494
+ resource usage of individual containers across a set of Pods, in order to scale the target resource.
495
+ This lets you configure scaling thresholds for the containers that matter most in a particular Pod.
496
+ For example, if you have a web application and a logging sidecar, you can scale based on the resource
497
+ use of the web application, ignoring the sidecar container and its resource use.
498
+ -->
499
+ ` HorizontalPodAutoscaler` 也支持容器指标源,这时 HPA 可以跟踪记录一组 Pods 中各个容器的
500
+ 资源用量,进而触发扩缩目标对象的操作。
501
+ 容器资源指标的支持使得你可以为特定 Pod 中最重要的容器配置规模缩放阈值。
502
+ 例如,如果你有一个 Web 应用和一个执行日志操作的边车容器,你可以基于 Web 应用的
503
+ 资源用量来执行扩缩,忽略边车容器的存在及其资源用量。
504
+
505
+ <!--
506
+ If you revise the target resource to have a new Pod specification with a different set of containers,
507
+ you should revise the HPA spec if that newly added container should also be used for
508
+ scaling. If the specified container in the metric source is not present or only present in a subset
509
+ of the pods then those pods are ignored and the recommendation is recalculated. See [Algorithm](#algorithm-details)
510
+ for more details about the calculation. To use container resources for autoscaling define a metric
511
+ source as follows :
512
+ -->
513
+ 如果你更改缩放目标对象,令其使用新的、包含一组不同的容器的 Pod 规约,你就需要
514
+ 修改 HPA 的规约才能基于新添加的容器来执行规模扩缩操作。
515
+ 如果指标源中指定的容器不存在或者仅存在于部分 Pods 中,那么这些 Pods 会被忽略,
516
+ HPA 会重新计算资源用量值。参阅[算法](#algorithm-details)小节进一步了解计算细节。
517
+ 要使用容器资源用量来完成自动扩缩,可以像下面这样定义指标源:
518
+
519
+ ` ` ` yaml
520
+ type: ContainerResource
521
+ containerResource:
522
+ name: cpu
523
+ container: application
524
+ target:
525
+ type: Utilization
526
+ averageUtilization: 60
527
+ ` ` `
528
+
529
+ <!--
530
+ In the above example the HPA controller scales the target such that the average utilization of the cpu
531
+ in the `application` container of all the pods is 60%.
532
+ -->
533
+ 在上面的例子中,HPA 控制器会对目标对象执行扩缩操作以确保所有 Pods 中
534
+ ` application` 容器的平均 CPU 用量为 60%。
535
+
536
+ {{< note >}}
537
+ <!--
538
+ If you change the name of a container that a HorizontalPodAutoscaler is tracking, you can
539
+ make that change in a specific order to ensure scaling remains available and effective
540
+ whilst the change is being applied. Before you update the resource that defines the container
541
+ (such as a Deployment), you should update the associated HPA to track both the new and
542
+ old container names. This way, the HPA is able to calculate a scaling recommendation
543
+ throughout the update process.
544
+ -->
545
+ 如果你要更改 HorizontalPodAutoscaler 所跟踪记录的容器的名称,你可以按一定顺序
546
+ 来执行这一更改,确保在应用更改的过程中用来判定扩缩行为的容器可用。
547
+ 在更新定义容器的资源(如 Deployment)之前,你需要更新相关的 HPA,使之能够同时
548
+ 跟踪记录新的和老的容器名称。这样,HPA 就能够在整个更新过程中继续计算并提供扩缩操作建议。
549
+
550
+ <!--
551
+ Once you have rolled out the container name change to the workload resource, tidy up by removing
552
+ the old container name from the HPA specification.
553
+ -->
554
+ 一旦你已经将容器名称变更这一操作应用到整个负载对象至上,就可以从 HPA
555
+ 的规约中去掉老的容器名称,完成清理操作。
556
+ {{< /note >}}
557
+
437
558
<!--
438
559
# # Support for multiple metrics
439
560
0 commit comments