Configuring VerticalPodAutoscaler (VPA)
目录
OverviewRelease NotesSupported Versionsv4.2 Release NotesLifecycle PolicyUnderstanding VerticalPodAutoscalersHow Does the VPA Work?Supported FeaturesPrerequisitesInstalling the Vertical Pod Autoscaler PluginUpgrading the Vertical Pod Autoscaler PluginCreating a VerticalPodAutoscalerUsing the CLIUsing the Web ConsoleAdvanced VPA ConfigurationUpdate Policy OptionsContainer Policy OptionsFollow-Up ActionsOverview
Alauda Container Platform Vertical Pod Autoscaler 基于开源的 Vertical Pod Autoscaler 组件。它通过分析 Pod 的历史资源使用数据,提供配额建议以提升资源利用率。
对于无状态和有状态应用,VerticalPodAutoscaler (VPA) 会根据应用需求自动推荐——并可选择性地应用——更合适的 CPU 和内存资源限制。这有助于确保 Pod 拥有足够的资源,同时提升整个集群的资源利用效率。
Release Notes
本节介绍 Alauda Container Platform Vertical Pod Autoscaler 插件的新功能、增强、废弃功能及已知问题。
Supported Versions
v4.2 Release Notes
v4.2.0
- 安全漏洞修复。
- 现支持独立发布。
Lifecycle Policy
下表列出了 Alauda Container Platform Vertical Pod Autoscaler 插件已发布版本的生命周期计划:
Understanding VerticalPodAutoscalers
VerticalPodAutoscaler (VPA) 用于基于 Pod 的历史使用模式,推荐或自动更新 Pod 的 CPU 和内存资源请求与限制。
创建 VPA 后,平台开始监控目标 Pod 的资源使用情况。收集到足够数据后,VPA 会计算推荐的资源值。根据配置的更新模式,VPA 可以自动应用这些推荐,或仅提供推荐供手动审核和应用。
通过分析资源使用趋势,VPA 有助于确保 Pod 获得所需资源而不过度配置,从而实现更高效的集群资源利用。
How Does the VPA Work?
VerticalPodAutoscaler (VPA) 扩展了 Pod 资源优化的概念。VPA 监控 Pod 的资源使用情况,并基于观察到的使用模式提供 CPU 和内存请求的推荐。
VPA 通过持续监控 Pod 资源使用并随着新数据的到来更新推荐来工作。VPA 支持以下模式:
- Off:VPA 仅提供推荐,不自动应用。
- Manual Adjustment:您可以根据 VPA 推荐手动调整资源配置。
重要提示:弹性伸缩(水平或垂直)在集群资源充足时效果最佳。资源紧张时,伸缩操作可能导致 Pod 处于
Pending状态。请确保集群资源充足,设置合理配额,并配置告警以监控伸缩事件。
Supported Features
VPA 基于历史使用模式提供资源推荐,帮助您优化 Pod 的 CPU 和内存配置。
重要提示:手动应用 VPA 推荐时会触发 Pod 重建,可能导致应用短暂中断。建议在生产环境的维护窗口期间应用推荐。
Prerequisites
使用 VPA 前,请确保:
-
集群已安装 Alauda Container Platform Vertical Pod Autoscaler 集群插件。
- 下载与您的平台版本兼容的最新插件包。
- 使用
violetCLI 工具将 Alauda Container Platform Vertical Pod Autoscalers 和 Alauda DevOps Pipelines 包上传至目标集群。有关violet的详细使用说明,请参见 CLI。
-
请确保当前集群已部署监控组件且运行正常。您可以点击平台右上角
> 平台健康状态 查看监控组件的部署及健康状态。
Installing the Vertical Pod Autoscaler Plugin
-
登录并进入 Administrators 页面。
-
点击 Marketplace > Cluster Plugins,进入 Cluster Plugins 列表页面。
-
找到 Alauda Container Platform Vertical Pod Autoscaler 集群插件,点击 Install,进入安装页面。
Upgrading the Vertical Pod Autoscaler Plugin
-
登录并进入 Administrators 页面。
-
点击 Marketplace > Cluster Plugins,进入 Cluster Plugins 列表页面。
-
找到 Alauda Container Platform Vertical Pod Autoscaler 集群插件,点击 Upgrade,进入安装页面。
Creating a VerticalPodAutoscaler
Using the CLI
您可以通过命令行界面定义 YAML 文件并使用 kubectl create 命令创建 VerticalPodAutoscaler。以下示例展示了针对 Deployment 对象的垂直 Pod 自动伸缩配置:
-
创建名为
vpa.yaml的 YAML 文件,内容如下:- 使用 autoscaling.k8s.io/v1 API。
- VPA 的名称。
- 指定目标工作负载对象。VPA 使用工作负载的选择器查找需要调整资源的 Pod。支持的工作负载类型包括 DaemonSet、Deployment、ReplicaSet、StatefulSet、ReplicationController、Job 和 CronJob。
- 指定要伸缩对象的 API 版本。
- 指定对象类型。
- VPA 应用的目标资源。
- 定义 VPA 如何应用推荐的更新策略。updateMode 可选:
- Auto:创建 Pod 时自动设置资源请求,并更新当前 Pod 至推荐资源请求。当前等同于“Recreate”。此模式可能导致应用停机。未来支持就地更新时,Auto 模式将采用该机制。
- Recreate:创建 Pod 时自动设置资源请求,并驱逐当前 Pod 以更新至推荐资源请求。不使用就地更新。
- Initial:仅在创建 Pod 时设置资源请求,之后不做修改。
- Off:不自动修改 Pod 资源请求,仅在 VPA 对象中提供推荐。
- 资源策略,可为不同容器设置具体策略。例如,将容器模式设为“Auto”表示会为该容器计算推荐,而“Off”表示不计算推荐。
- 应用于 Pod 中所有容器。
- 设置模式为 Auto 或 Off。Auto 表示为该容器生成推荐,Off 表示不生成推荐。
-
应用 YAML 文件创建 VPA:
示例输出:
-
创建 VPA 后,可通过以下命令查看推荐:
示例输出(部分):
Using the Web Console
-
登录并进入 Container Platform。
-
在左侧导航栏点击 Workloads > Deployments。
-
点击 Deployment Name。
-
向下滚动至 Elastic Scaling 区域,点击右侧的 Update。
-
选择 Vertical Scaling 并配置伸缩规则。
-
点击 Update。
Advanced VPA Configuration
Update Policy Options
updateMode: "Off"- VPA 仅提供推荐,不自动应用。您可根据需要手动应用推荐。updateMode: "Auto"- 创建 Pod 时自动设置资源请求,并更新当前 Pod 至推荐值。当前等同于“Recreate”。updateMode: "Recreate"- 创建 Pod 时自动设置资源请求,并驱逐当前 Pod 以更新至推荐值。updateMode: "Initial"- 仅在创建 Pod 时设置资源请求,之后不做修改。minReplicas: <number>- 最小副本数。确保在 Updater 驱逐 Pod 时,至少保持该数量的 Pod 可用。必须大于 0。
Container Policy Options
containerName: "*"- 应用于 Pod 中所有容器。mode: "Auto"- 自动为容器生成推荐。mode: "Off"- 不为容器生成推荐。
注意:
- VPA 推荐基于历史使用数据,Pod 运行数天后推荐才会准确。
- 在 Auto 模式应用 VPA 推荐时会触发 Pod 重建,可能导致应用短暂中断。
Follow-Up Actions
配置 VPA 后,可在 Elastic Scaling 区域查看目标容器的 CPU 和内存资源限制推荐值。在 Containers 区域,选择目标容器标签页,点击 Resource Limits 右侧图标,根据推荐值更新资源限制。