You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过manifest.yaml在PCF中启用Spring Boot应用自动扩缩容

解决PCF Spring Boot应用自动扩缩容的Manifest配置问题

错误原因分析

你遇到的All top level service binding parameters are required报错,核心问题是在服务绑定阶段错误传入了参数。PCF的App Autoscaler服务不支持在绑定应用时通过parameters字段配置缩放规则,这些参数属于服务实例的配置项,而非绑定参数。同时,你之前绑定服务后自动扩缩容未生效,是因为仅绑定服务但未配置任何缩放策略和实例范围。

正确配置步骤

步骤1:修正Manifest配置

首先移除services列表中myappautoscaler下的parameters节点,仅保留服务绑定声明:

...
dev:
  pcf_urls: ["abc.dev.com"]
  pcf_space: "dev"
  pcf_env:"dev"
  pcf_buildpack: java_buildpack
  pcf_bindServices:
    - "mycredhubservice"
    - "myappautoscaler"
  applications:
  - name: my-app
    instances: 1
    memory: 1G
    env:
       SPRING_PROFILES_ACTIVE: dev
       ...
       ...
    services:
      - mycredhubservice 
      - myappautoscaler 

修改后部署不会再触发参数缺失的报错。

步骤2:配置自动扩缩容规则

绑定服务后,需通过PCF CLI或Apps Manager配置缩放策略,以下是CLI方式的常用命令:

  1. 设置实例数量范围:
cf autoscaling-set-instance-limits my-app --min 1 --max 3
  1. 添加CPU使用率缩放规则(示例:CPU超过70%时扩容1个实例,低于30%时缩容1个):
cf autoscaling-add-rule my-app cpu --threshold 70 --above 1
cf autoscaling-add-rule my-app cpu --threshold 30 --below -1
  1. 添加内存使用率缩放规则(示例:内存超过75%时扩容1个实例,低于25%时缩容1个):
cf autoscaling-add-rule my-app memory --threshold 75 --above 1
cf autoscaling-add-rule my-app memory --threshold 25 --below -1

可选:创建服务实例时预配置规则

如果希望在创建Autoscaler服务实例时就定义好缩放规则,可使用cf create-service命令传入配置JSON,后续绑定应用时无需额外配置:

cf create-service app-autoscaler standard myappautoscaler -c '{
  "instance_min_count": 1,
  "instance_max_count": 3,
  "scaling_rules": [
    {
      "metric_type": "cpu",
      "threshold": 70,
      "operator": ">",
      "adjustment": "+1"
    },
    {
      "metric_type": "cpu",
      "threshold": 30,
      "operator": "<",
      "adjustment": "-1"
    },
    {
      "metric_type": "memory",
      "threshold": 75,
      "operator": ">",
      "adjustment": "+1"
    },
    {
      "metric_type": "memory",
      "threshold": 25,
      "operator": "<",
      "adjustment": "-1"
    }
  ]
}'

验证配置

部署应用并完成规则配置后,可通过以下命令查看当前自动扩缩容设置:

cf autoscaling my-app

也可登录PCF Apps Manager,进入应用的Autoscaler面板查看和调整规则。

内容的提问来源于stack exchange,提问作者Keerthana Hemachandran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 13:25:58