Azure Kubernetes 服务 (AKS) 中的应用程序缩放选项Scaling options for applications in Azure Kubernetes Service (AKS)

在 Azure Kubernetes 服务 (AKS) 中运行应用程序时,可能需要增加或减少计算资源量。As you run applications in Azure Kubernetes Service (AKS), you may need to increase or decrease the amount of compute resources. 随着所需应用程序实例数量的变化,可能还需要更改基础 Kubernetes 节点的数量。As the number of application instances you need change, the number of underlying Kubernetes nodes may also need to change. 可能还需要快速预配大量其他应用程序实例。You also might need to quickly provision a large number of additional application instances.

本文介绍有助于在 AKS 中缩放应用程序的核心概念:This article introduces the core concepts that help you scale applications in AKS:

手动缩放 Pod 或节点Manually scale pods or nodes

可以手动缩放副本 (Pod) 和节点,以测试应用程序如何响应可用资源和状态的更改。You can manually scale replicas (pods) and nodes to test how your application responds to a change in available resources and state. 手动缩放资源还可以定义用于维持固定成本的设定数量的资源,例如节点数。Manually scaling resources also lets you define a set amount of resources to use to maintain a fixed cost, such as the number of nodes. 若要手动缩放,请定义副本或节点计数。To manually scale, you define the replica or node count. 然后,Kubernetes API 根据该副本或节点计数计划创建其他 Pod 或排空节点。The Kubernetes API then schedules creating additional pods or draining nodes based on that replica or node count.

缩减节点时,Kubernetes API 将调用与群集使用的计算类型绑定的相关 Azure 计算 API。When scaling down nodes, the Kubernetes API calls the relevant Azure Compute API tied to the compute type used by your cluster. 例如,对于基于 VM 规模集构建的群集,选择要删除的节点的逻辑由 VM 规模集 API 确定。For example, for clusters built on VM Scale Sets the logic for selecting which nodes to remove is determined by the VM Scale Sets API. 若要详细了解如何在缩减节点时选择要删除的节点,请参阅 VMSS 常见问题解答To learn more about how nodes are selected for removal on scale down, see the VMSS FAQ.

若要开始使用手动缩放 Pod 和节点,请参阅在 AKS 中缩放应用程序To get started with manually scaling pods and nodes see Scale applications in AKS.

水平 Pod 自动缩放程序Horizontal pod autoscaler

Kubernetes 使用水平 Pod 自动缩放程序 (HPA) 来监视资源需求并自动缩放副本数量。Kubernetes uses the horizontal pod autoscaler (HPA) to monitor the resource demand and automatically scale the number of replicas. 默认情况下,水平 Pod 自动缩放程序每隔 30 秒检查一次指标 API,以了解副本计数所需的任何更改。By default, the horizontal pod autoscaler checks the Metrics API every 30 seconds for any required changes in replica count. 当需要进行更改时,副本的数量会相应增加或减少。When changes are required, the number of replicas is increased or decreased accordingly. 水平 Pod 自动缩放程序与已经为 Kubernetes 1.8+ 部署了指标服务器的 AKS 群集配合使用。Horizontal pod autoscaler works with AKS clusters that have deployed the Metrics Server for Kubernetes 1.8+.

Kubernetes 水平 Pod 自动缩放

为给定部署配置水平 Pod 自动缩放程序时,请定义可运行的最小和最大副本数。When you configure the horizontal pod autoscaler for a given deployment, you define the minimum and maximum number of replicas that can run. 还可以定义指标以监视任何缩放决策并以此为依据,例如 CPU 使用情况。You also define the metric to monitor and base any scaling decisions on, such as CPU usage.

若要开始使用 AKS 中的水平 Pod 自动缩放程序,请参阅在 AKS 中自动缩放 PodTo get started with the horizontal pod autoscaler in AKS, see Autoscale pods in AKS.

缩放事件的冷却时间Cooldown of scaling events

由于水平 Pod 自动缩放程序每 30 秒检查一次指标 API,因此在进行另一次检查之前,先前的缩放事件可能尚未成功完成。As the horizontal pod autoscaler checks the Metrics API every 30 seconds, previous scale events may not have successfully completed before another check is made. 此行为可能导致水平 Pod 自动缩放程序会在上一个缩放事件能够接收应用程序工作负荷且需要对资源进行相应调整之前更改副本数。This behavior could cause the horizontal pod autoscaler to change the number of replicas before the previous scale event could receive application workload and the resource demands to adjust accordingly.

若要最大程度地减少争用事件,请设置延迟值。To minimize race events, a delay value is set. 此值定义水平 Pod 自动缩放程序在一个缩放事件之后必须等待多长时间才能触发另一个缩放事件。This value defines how long the horizontal pod autoscaler must wait after a scale event before another scale event can be triggered. 此行为允许新副本计数生效,指标 API 反映分布式工作负荷。This behavior allows the new replica count to take effect and the Metrics API to reflect the distributed workload. 从 Kubernetes 1.12 开始,纵向扩展事件没有延迟,但是纵向缩减事件的延迟默认为 5 分钟。There is no delay for scale-up events as of Kubernetes 1.12, however the delay on scale down events is defaulted to 5 minutes.

目前,无法从默认值调整这些冷却时间值。Currently, you can't tune these cooldown values from the default.

后续步骤Next steps

若要开始缩放应用程序,请首先按照使用 Azure CLI 创建 AKS 群集的快速入门进行操作。To get started with scaling applications, first follow the quickstart to create an AKS cluster with the Azure CLI. 然后,可以开始手动或自动缩放 AKS 群集中的应用程序:You can then start to manually or automatically scale applications in your AKS cluster:

有关核心 Kubernetes 和 AKS 概念的详细信息,请参阅以下文章:For more information on core Kubernetes and AKS concepts, see the following articles: