横向 pod 自动扩缩器 (HPA) 作为 Kubernetes API 资源(HPA 对象)和控制循环(HPA 控制器)实现,后者定期根据当前资源利用率计算所需副本的数量。然后,HPA 控制器将该数量传递给实现 Scale 子资源的目标对象。实际扩缩会委托给底层对象及其控制器。有关详情,请参阅 Kubernetes 文档。
自动扩缩器如何确定何时扩缩
HPA 控制器根据在每个 HorizontalPodAutoscaler 定义中指定的指标定期查询资源利用率。控制器会从每个 pod 的资源指标 API 获取该指标。接着,控制器将利用率值以等效资源请求的百分比的形式计算。然后,系统会根据当前百分比和所需的百分比来计算所需的副本数量。您可以在 Kubernetes 文档中详细了解自动扩缩算法。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Autoscaling\n\nKf leverages the Kubernetes Horizontal Pod Autoscaler (HPA)\nto automatically scale the number of Pods in a App. When autoscaling is enabled\nfor an App, an HPA object is created and bound to the App object. It then dynamically\ncalculates the target scale and sets it for the App.\n\nHow Kf scaling works\n--------------------\n\nThe number of Pods that are deployed for a Kf App is\ncontrolled by its underlying Deployment object's `replica` field. The target\nnumber of Deployment replicas is set through the App's `replicas` field.\n\nScaling can be done manually with the [`kf scale`](/migrate/kf/docs/2.1/cli/kf-scale)\ncommand. This command is disabled when autoscaling is enabled to avoid conflicting targets.\n\nHow the Kubernetes Horizontal Pod Autoscaler works\n--------------------------------------------------\n\nThe Horizontal Pod Autoscaler (HPA) is implemented as a Kubernetes API resource\n(the HPA object) and a control loop (the HPA controller) which periodically\ncalculates the number of desired replicas based on current resource utilization.\nThe HPA controller then passes the number to the target object that implements the\nScale subresource. The actual scaling is delegated to the underlying object and\nits controller. You can find more information in the [Kubernetes documentation](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/).\n\n### How the Autoscaler determines when to scale\n\nPeriodically, the HPA controller queries the resource utilization against\nthe metrics specified in each HorizontalPodAutoscaler definition. The controller\nobtains the metrics from the resource metrics API for each Pod. Then the\ncontroller calculates the utilization value as a percentage of the equivalent\nresource request. The desired number of replicas is then calculated based on the\nratio of current percentage and desired percentage. You can read more about the\n[autoscaling algorithm](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#algorithm-details) in the Kubernetes documentation.\n\n### Metrics\n\nKf uses HPA v1 which only supports CPU as the target\nmetric.\n\nHow the Kubernetes Horizontal Autoscaler works with Kf\n------------------------------------------------------\n\nWhen autoscaling is enabled for a Kf App, the Kf\ncontroller will create an HPA object based on the scaling limits and rules\nspecified on the App. Then the HPA controller fetches the specs from the HPA\nobject and scales the App accordingly.\n\nThe HPA object will be deleted if Autoscaling is disabled or if the\ncorresponding App is deleted."]]