cf-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloud Foundry CLI Skill
Cloud Foundry CLI Skill
You are an expert in the Cloud Foundry CLI (v8). Help users construct correct commands, write manifests, automate deployments, manage services, and troubleshoot issues. The goal is to save the user from constantly running by giving them precise, runnable commands.
cfcf helpImportant: v7 and v6 are no longer maintained. Always use v8 syntax. The v8 CLI is backed by the CC API v3.
你是 Cloud Foundry CLI (v8) 的专家。帮助用户构造正确的 命令、编写 manifest、自动化部署、管理服务并排查问题。目标是避免用户频繁运行 ,直接为他们提供精确、可运行的命令。
cfcf help重要提示: v7 和 v6 已不再维护。始终使用 v8 语法。v8 CLI 由 CC API v3 支持。
Installation
安装
Install from the V8 Installation Guide. Available via package managers (Homebrew, apt, yum, Chocolatey) or binary download.
Verify:
cf version从 V8 安装指南 安装。可通过包管理器(Homebrew、apt、yum、Chocolatey)或二进制下载方式获得。
验证:
cf versionAuthentication & Targeting
认证与目标设置
cf api
cf api
Sets the API endpoint for your Cloud Foundry instance.
bash
cf api https://api.example.com
cf api https://api.example.com --skip-ssl-validation # dev/self-signed certs only
cf api # show current API设置 Cloud Foundry 实例的 API 端点。
bash
cf api https://api.example.com
cf api https://api.example.com --skip-ssl-validation # dev/self-signed certs only
cf api # show current APIcf login
cf login
Interactive login — prompts for anything not provided:
bash
cf login # fully interactive
cf login -a https://api.example.com # set API + login
cf login -a https://api.example.com -u user@example.com # preset username
cf login -a https://api.example.com --sso # SSO via one-time passcode
cf login -o my-org -s dev # target org + space on login| Flag | Description |
|---|---|
| API endpoint URL |
| Username |
| Password (avoid — recorded in shell history) |
| Target organization |
| Target space |
| SSO via one-time passcode from the login URL |
| Provide SSO passcode directly |
| Specify identity provider origin |
| Skip SSL cert verification |
交互式登录 — 未提供的参数会提示输入:
bash
cf login # fully interactive
cf login -a https://api.example.com # set API + login
cf login -a https://api.example.com -u user@example.com # preset username
cf login -a https://api.example.com --sso # SSO via one-time passcode
cf login -o my-org -s dev # target org + space on login| 标志 | 说明 |
|---|---|
| API 端点 URL |
| 用户名 |
| 密码(避免使用 — 会记录在 shell 历史中) |
| 目标组织 |
| 目标空间 |
| 通过登录 URL 提供的一次性口令进行 SSO |
| 直接提供 SSO 口令 |
| 指定身份提供方来源 |
| 跳过 SSL 证书验证 |
cf auth
cf auth
Non-interactive authentication for scripts and CI/CD:
bash
cf auth username password
cf auth username password --origin ldap
cf auth --client-credentials # uses CF_USERNAME and CF_PASSWORD env vars用于脚本和 CI/CD 的非交互式认证:
bash
cf auth username password
cf auth username password --origin ldap
cf auth --client-credentials # uses CF_USERNAME and CF_PASSWORD env varscf target
cf target
Switches org and space context after login:
bash
cf target -o my-org -s dev
cf target -s staging # switch space only
cf target # show current target登录后切换组织和空间上下文:
bash
cf target -o my-org -s dev
cf target -s staging # switch space only
cf target # show current targetcf logout
cf logout
bash
cf logoutbash
cf logoutApp Lifecycle
应用生命周期
cf push (alias: p
)
pcf push(别名:p
)
pThe most important command — deploys an app.
bash
cf push my-app # push from current dir
cf push my-app -p ./build # push specific path
cf push my-app -f manifest.yml # use specific manifest
cf push my-app -b nodejs_buildpack # explicit buildpack
cf push my-app -i 3 -m 512M -k 1G # 3 instances, 512MB RAM, 1GB disk
cf push my-app --no-start # stage but don't start
cf push my-app --no-route # no route (workers/tasks)
cf push my-app --random-route # generate random route
cf push my-app --strategy rolling # zero-downtime rolling deploy
cf push my-app --docker-image my-registry/my-image:tag # docker image
cf push -f manifest.yml --var host=my-host # variable substitution
cf push -f manifest.yml --vars-file vars.yml # vars from fileKey flags: buildpack, command, manifest, instances, disk, memory, path, stack, timeout, health-check-type (//), , (password via ), , , , , , , , (/null), , , .
-b-c-f-i-k-m-p-s-t-uporthttpprocess-o/--docker-image--docker-usernameCF_DOCKER_PASSWORD--droplet--endpoint--no-manifest--no-route--no-start--no-wait--random-route--strategyrolling--task--var KEY=VALUE--vars-file PATHPush env vars: , (min), (min).
CF_DOCKER_PASSWORDCF_STAGING_TIMEOUT=15CF_STARTUP_TIMEOUT=5最重要的命令 — 部署应用。
bash
cf push my-app # push from current dir
cf push my-app -p ./build # push specific path
cf push my-app -f manifest.yml # use specific manifest
cf push my-app -b nodejs_buildpack # explicit buildpack
cf push my-app -i 3 -m 512M -k 1G # 3 instances, 512MB RAM, 1GB disk
cf push my-app --no-start # stage but don't start
cf push my-app --no-route # no route (workers/tasks)
cf push my-app --random-route # generate random route
cf push my-app --strategy rolling # zero-downtime rolling deploy
cf push my-app --docker-image my-registry/my-image:tag # docker image
cf push -f manifest.yml --var host=my-host # variable substitution
cf push -f manifest.yml --vars-file vars.yml # vars from file关键标志: buildpack、 command、 manifest、 instances、 disk、 memory、 path、 stack、 timeout、 health-check-type(//)、、(密码通过 提供)、、、、、、、、(/null)、、、。
-b-c-f-i-k-m-p-s-t-uporthttpprocess-o/--docker-image--docker-usernameCF_DOCKER_PASSWORD--droplet--endpoint--no-manifest--no-route--no-start--no-wait--random-route--strategyrolling--task--var KEY=VALUE--vars-file PATHPush 环境变量: 、(分钟)、(分钟)。
CF_DOCKER_PASSWORDCF_STAGING_TIMEOUT=15CF_STARTUP_TIMEOUT=5App Management
应用管理
bash
cf apps # list all apps in current space
cf app my-app # show app details (instances, memory, routes, state)
cf start my-app # start a stopped app
cf stop my-app # stop a running app
cf restart my-app # restart (re-containerize, same droplet)
cf restage my-app # restage (re-build droplet from source)
cf delete my-app # delete app (prompts for confirmation)
cf delete my-app -f # force delete (no confirmation)
cf delete my-app -r # also delete mapped routes
cf rename my-app new-name # rename an app
cf scale my-app -i 5 # scale to 5 instances
cf scale my-app -m 1G -k 2G # change memory and disk
cf scale my-app -i 5 -m 1G # scale instances and memory togetherbash
cf apps # list all apps in current space
cf app my-app # show app details (instances, memory, routes, state)
cf start my-app # start a stopped app
cf stop my-app # stop a running app
cf restart my-app # restart (re-containerize, same droplet)
cf restage my-app # restage (re-build droplet from source)
cf delete my-app # delete app (prompts for confirmation)
cf delete my-app -f # force delete (no confirmation)
cf delete my-app -r # also delete mapped routes
cf rename my-app new-name # rename an app
cf scale my-app -i 5 # scale to 5 instances
cf scale my-app -m 1G -k 2G # change memory and disk
cf scale my-app -i 5 -m 1G # scale instances and memory togetherDeployment & Rollback
部署与回滚
bash
cf push my-app --strategy rolling # zero-downtime rolling deploy
cf cancel-deployment my-app # cancel an in-progress deploymentbash
cf push my-app --strategy rolling # zero-downtime rolling deploy
cf cancel-deployment my-app # cancel an in-progress deploymentLogs & Events
日志与事件
bash
cf logs my-app # tail live logs
cf logs my-app --recent # dump recent logs
cf events my-app # show recent app events (crashes, scaling, etc.)bash
cf logs my-app # tail live logs
cf logs my-app --recent # dump recent logs
cf events my-app # show recent app events (crashes, scaling, etc.)SSH
SSH
bash
cf ssh my-app # SSH into first instance
cf ssh my-app -i 2 # SSH into instance index 2
cf ssh my-app -c "cat /app/config.yml" # run a command and exit
cf enable-ssh my-app / cf disable-ssh my-app / cf ssh-enabled my-appbash
cf ssh my-app # SSH into first instance
cf ssh my-app -i 2 # SSH into instance index 2
cf ssh my-app -c "cat /app/config.yml" # run a command and exit
cf enable-ssh my-app / cf disable-ssh my-app / cf ssh-enabled my-appTasks
任务
bash
cf run-task my-app --command "rake db:migrate" # run a one-off task
cf run-task my-app -c "rake db:migrate" -m 512M # with memory limit
cf tasks my-app # list tasks
cf terminate-task my-app TASK_ID # cancel a running taskbash
cf run-task my-app --command "rake db:migrate" # run a one-off task
cf run-task my-app -c "rake db:migrate" -m 512M # with memory limit
cf tasks my-app # list tasks
cf terminate-task my-app TASK_ID # cancel a running taskEnvironment Variables
环境变量
bash
cf env my-app # show all env vars (user + system)
cf set-env my-app DATABASE_URL "postgres://..." # set a var
cf unset-env my-app DATABASE_URL # remove a var
cf restage my-app # restage for changes to take effectAfter or , you need to restage or restart the app for changes to apply.
set-envunset-envbash
cf env my-app # show all env vars (user + system)
cf set-env my-app DATABASE_URL "postgres://..." # set a var
cf unset-env my-app DATABASE_URL # remove a var
cf restage my-app # restage for changes to take effect在 或 后,你需要 restage 或 restart 应用,更改才会生效。
set-envunset-envHealth Checks
健康检查
bash
cf get-health-check my-app
cf set-health-check my-app http --endpoint /health
cf set-health-check my-app port
cf set-health-check my-app processbash
cf get-health-check my-app
cf set-health-check my-app http --endpoint /health
cf set-health-check my-app port
cf set-health-check my-app processPackages & Droplets
包与 Droplet
bash
cf packages my-app / cf create-package my-app # list / upload packages
cf droplets my-app / cf set-droplet my-app GUID # list / set active droplet
cf download-droplet my-app / cf stage-package my-app --package-guid GUIDbash
cf packages my-app / cf create-package my-app # list / upload packages
cf droplets my-app / cf set-droplet my-app GUID # list / set active droplet
cf download-droplet my-app / cf stage-package my-app --package-guid GUIDManifests
Manifest(清单文件)
The manifest () declares app configuration. CF reads it automatically from the current directory during .
manifest.ymlcf pushyaml
---
applications:
- name: my-app
memory: 512M
disk_quota: 1G
instances: 2
buildpacks:
- nodejs_buildpack
command: node server.js
health-check-type: http
health-check-http-endpoint: /health
timeout: 120
stack: cflinuxfs4
env:
NODE_ENV: production
LOG_LEVEL: info
routes:
- route: my-app.example.com
- route: my-app.example.com/api
services:
- my-database
- my-redis
processes:
- type: web
instances: 2
memory: 512M
- type: worker
instances: 1
memory: 256M
command: node worker.js
health-check-type: process
no-route: trueVariable substitution in manifests:
yaml
undefinedmanifest()声明应用配置。CF 会在 时自动从当前目录读取它。
manifest.ymlcf pushyaml
---
applications:
- name: my-app
memory: 512M
disk_quota: 1G
instances: 2
buildpacks:
- nodejs_buildpack
command: node server.js
health-check-type: http
health-check-http-endpoint: /health
timeout: 120
stack: cflinuxfs4
env:
NODE_ENV: production
LOG_LEVEL: info
routes:
- route: my-app.example.com
- route: my-app.example.com/api
services:
- my-database
- my-redis
processes:
- type: web
instances: 2
memory: 512M
- type: worker
instances: 1
memory: 256M
command: node worker.js
health-check-type: process
no-route: truemanifest 中的变量替换:
yaml
undefinedmanifest.yml
manifest.yml
applications:
- name: ((app-name)) instances: ((instances))
```bash
cf push --var app-name=my-app --var instances=3applications:
- name: ((app-name)) instances: ((instances))
```bash
cf push --var app-name=my-app --var instances=3or from a file:
or from a file:
cf push --vars-file production.yml
**Create manifest from running app:**
```bash
cf create-app-manifest my-app # generates manifest.yml from current state
cf create-app-manifest my-app -p ./out # write to specific directorycf push --vars-file production.yml
**从运行中的应用生成 manifest:**
```bash
cf create-app-manifest my-app # generates manifest.yml from current state
cf create-app-manifest my-app -p ./out # write to specific directoryServices
服务
Marketplace
Marketplace(服务市场)
bash
cf marketplace # list all available services
cf marketplace -e SERVICE_NAME # show plans for a specific service
cf marketplace -s SERVICE_NAME # alias for -ebash
cf marketplace # list all available services
cf marketplace -e SERVICE_NAME # show plans for a specific service
cf marketplace -s SERVICE_NAME # alias for -eService Instances
服务实例
bash
cf services # list service instances in current space
cf service my-db # show details for a service instancebash
cf services # list service instances in current space
cf service my-db # show details for a service instanceCreate
Create
cf create-service SERVICE PLAN NAME # create from marketplace
cf create-service postgres standard my-db
cf create-service postgres standard my-db -c '{"storage":"50gb"}' # with params
cf create-service postgres standard my-db -c config.json # params from file
cf create-service postgres standard my-db -t "env:prod,team:api" # with tags
cf create-service SERVICE PLAN NAME # create from marketplace
cf create-service postgres standard my-db
cf create-service postgres standard my-db -c '{"storage":"50gb"}' # with params
cf create-service postgres standard my-db -c config.json # params from file
cf create-service postgres standard my-db -t "env:prod,team:api" # with tags
Update
Update
cf update-service my-db -p premium # change plan
cf update-service my-db -c '{"key":"val"}' # update params
cf upgrade-service my-db # upgrade to latest version
cf update-service my-db -p premium # change plan
cf update-service my-db -c '{"key":"val"}' # update params
cf upgrade-service my-db # upgrade to latest version
Delete
Delete
cf delete-service my-db
cf delete-service my-db -f # no confirmation
cf rename-service my-db new-db-name
undefinedcf delete-service my-db
cf delete-service my-db -f # no confirmation
cf rename-service my-db new-db-name
undefinedBinding & Unbinding
绑定与解绑
bash
cf bind-service my-app my-db # bind service to app
cf bind-service my-app my-db -c '{"role":"admin"}' # with config
cf unbind-service my-app my-db # unbind
cf restage my-app # restage to pick up new bindingsBinding injects credentials into env var.
VCAP_SERVICESbash
cf bind-service my-app my-db # bind service to app
cf bind-service my-app my-db -c '{"role":"admin"}' # with config
cf unbind-service my-app my-db # unbind
cf restage my-app # restage to pick up new bindings绑定会将凭据注入 环境变量。
VCAP_SERVICESService Keys
服务密钥
Service keys let you get credentials without binding to an app:
bash
cf create-service-key my-db my-key
cf create-service-key my-db my-key -c '{"permissions":"read-only"}'
cf service-keys my-db # list keys
cf service-key my-db my-key # show credentials
cf delete-service-key my-db my-key服务密钥让你无需绑定到应用即可获取凭据:
bash
cf create-service-key my-db my-key
cf create-service-key my-db my-key -c '{"permissions":"read-only"}'
cf service-keys my-db # list keys
cf service-key my-db my-key # show credentials
cf delete-service-key my-db my-keyUser-Provided Services
用户提供的服务
For external services not in the marketplace:
bash
undefined用于市场外的外部服务:
bash
undefinedInteractive (prompts for each param)
Interactive (prompts for each param)
cf create-user-provided-service my-ext -p "host, port, username, password"
cf create-user-provided-service my-ext -p "host, port, username, password"
Non-interactive (JSON)
Non-interactive (JSON)
cf cups my-ext -p '{"host":"db.example.com","port":"5432","user":"admin","password":"secret"}'
cf cups my-ext -p '{"host":"db.example.com","port":"5432","user":"admin","password":"secret"}'
Syslog drain
Syslog drain
cf cups my-logger -l syslog://logs.example.com:514
cf cups my-logger -l syslog://logs.example.com:514
Route service
Route service
cf cups my-proxy -r https://proxy.example.com
cf cups my-proxy -r https://proxy.example.com
Update
Update
cf update-user-provided-service my-ext -p '{"password":"new-secret"}'
`cups` is the alias for `create-user-provided-service`, `uups` for `update-user-provided-service`.cf update-user-provided-service my-ext -p '{"password":"new-secret"}'
`cups` 是 `create-user-provided-service` 的别名,`uups` 是 `update-user-provided-service` 的别名。Service Sharing & Route Services
服务共享与路由服务
bash
cf share-service my-db -s other-space [-o other-org]
cf unshare-service my-db -s other-space
cf bind-route-service example.com my-proxy --hostname my-app
cf unbind-route-service example.com my-proxy --hostname my-appbash
cf share-service my-db -s other-space [-o other-org]
cf unshare-service my-db -s other-space
cf bind-route-service example.com my-proxy --hostname my-app
cf unbind-route-service example.com my-proxy --hostname my-appRoutes & Domains
路由与域名
Domains
域名
bash
cf domains # list all domains
cf create-private-domain my-org apps.internal # internal/private domain
cf delete-private-domain apps.internal
cf create-shared-domain shared.example.com # shared across all orgs
cf delete-shared-domain shared.example.com
cf router-groups # list router groupsbash
cf domains # list all domains
cf create-private-domain my-org apps.internal # internal/private domain
cf delete-private-domain apps.internal
cf create-shared-domain shared.example.com # shared across all orgs
cf delete-shared-domain shared.example.com
cf router-groups # list router groupsRoutes
路由
bash
cf routes # list all routes in current space
cf route my-app.example.com # show route details
cf create-route example.com --hostname my-app # create route
cf create-route apps.internal --hostname backend # internal route
cf create-route example.com --hostname my-app --path /api # with path
cf map-route my-app example.com --hostname my-app # map route to app
cf unmap-route my-app example.com --hostname my-app # unmap
cf delete-route example.com --hostname my-app # delete route
cf delete-orphaned-routes # clean up unmapped routes
cf check-route example.com --hostname my-app # check if route existsbash
cf routes # list all routes in current space
cf route my-app.example.com # show route details
cf create-route example.com --hostname my-app # create route
cf create-route apps.internal --hostname backend # internal route
cf create-route example.com --hostname my-app --path /api # with path
cf map-route my-app example.com --hostname my-app # map route to app
cf unmap-route my-app example.com --hostname my-app # unmap
cf delete-route example.com --hostname my-app # delete route
cf delete-orphaned-routes # clean up unmapped routes
cf check-route example.com --hostname my-app # check if route existsOrgs & Spaces
组织与空间
Organizations
组织
bash
cf orgs # list orgs
cf org my-org # show org details (spaces, domains, quotas)
cf create-org my-org
cf delete-org my-org
cf rename-org my-org new-orgbash
cf orgs # list orgs
cf org my-org # show org details (spaces, domains, quotas)
cf create-org my-org
cf delete-org my-org
cf rename-org my-org new-orgSpaces
空间
bash
cf spaces # list spaces in current org
cf space dev # show space details
cf create-space staging
cf delete-space staging
cf rename-space staging production
cf apply-manifest -f manifest.yml # apply manifest to current spacebash
cf spaces # list spaces in current org
cf space dev # show space details
cf create-space staging
cf delete-space staging
cf rename-space staging production
cf apply-manifest -f manifest.yml # apply manifest to current spaceSpace SSH
空间 SSH
cf allow-space-ssh SPACEcf disallow-space-ssh SPACEcf space-ssh-allowed SPACEcf allow-space-ssh SPACEcf disallow-space-ssh SPACEcf space-ssh-allowed SPACEUser & Role Management
用户与角色管理
bash
cf org-users my-org # list org users
cf space-users my-org dev # list space usersbash
cf org-users my-org # list org users
cf space-users my-org dev # list space usersOrg roles: OrgManager, BillingManager, OrgAuditor
Org roles: OrgManager, BillingManager, OrgAuditor
cf set-org-role user@example.com my-org OrgManager
cf unset-org-role user@example.com my-org OrgManager
cf set-org-role user@example.com my-org OrgManager
cf unset-org-role user@example.com my-org OrgManager
Space roles: SpaceManager, SpaceDeveloper, SpaceAuditor, SpaceSupporter
Space roles: SpaceManager, SpaceDeveloper, SpaceAuditor, SpaceSupporter
cf set-space-role user@example.com my-org dev SpaceDeveloper
cf unset-space-role user@example.com my-org dev SpaceDeveloper
undefinedcf set-space-role user@example.com my-org dev SpaceDeveloper
cf unset-space-role user@example.com my-org dev SpaceDeveloper
undefinedAdministration
管理操作
Buildpacks: (list), , , .
cf buildpackscf create-buildpack NAME PATH POSITIONcf update-buildpack NAME -p PATHcf delete-buildpack NAMENetwork policies: , , .
cf network-policiescf add-network-policy APP DEST --protocol tcp --port 8080cf remove-network-policy APP DEST --protocol tcp --port 8080Security groups: , , , (global default).
cf security-groupscf create-security-group NAME rules.jsoncf bind-security-group NAME ORG SPACE --lifecycle runningcf bind-running-security-group NAMEQuotas: , , . Space quotas: , , .
cf org-quotascf create-org-quota NAME -m 10G -i 100 -r 50 -s 20cf set-org-quota ORG QUOTAcf space-quotascf create-space-quota NAME -m 5Gcf set-space-quota SPACE QUOTAFeature flags: , , .
cf feature-flagscf enable-feature-flag FLAGcf disable-feature-flag FLAGBuildpack: (列表)、、、。
cf buildpackscf create-buildpack NAME PATH POSITIONcf update-buildpack NAME -p PATHcf delete-buildpack NAME网络策略: 、、。
cf network-policiescf add-network-policy APP DEST --protocol tcp --port 8080cf remove-network-policy APP DEST --protocol tcp --port 8080安全组: 、、、(全局默认)。
cf security-groupscf create-security-group NAME rules.jsoncf bind-security-group NAME ORG SPACE --lifecycle runningcf bind-running-security-group NAME配额: 、、。空间配额:、、。
cf org-quotascf create-org-quota NAME -m 10G -i 100 -r 50 -s 20cf set-org-quota ORG QUOTAcf space-quotascf create-space-quota NAME -m 5Gcf set-space-quota SPACE QUOTA功能开关: 、、。
cf feature-flagscf enable-feature-flag FLAGcf disable-feature-flag FLAGAdvanced Commands
高级命令
cf curl
cf curl
Direct API calls — invaluable for automation and debugging:
bash
cf curl /v3/apps # list apps via API
cf curl /v3/apps/APP_GUID # get specific app
cf curl /v3/apps -X POST -d '{"name":"my-app","relationships":{"space":{"data":{"guid":"SPACE_GUID"}}}}'
cf curl "/v3/apps?names=my-app" # query by name直接调用 API — 对自动化和调试非常有价值:
bash
cf curl /v3/apps # list apps via API
cf curl /v3/apps/APP_GUID # get specific app
cf curl /v3/apps -X POST -d '{"name":"my-app","relationships":{"space":{"data":{"guid":"SPACE_GUID"}}}}'
cf curl "/v3/apps?names=my-app" # query by namecf config
cf config
bash
cf config --trace true # enable API tracing (like CF_TRACE=true)
cf config --trace /tmp/cf-trace.log # trace to file
cf config --color false # disable colored output
cf config --locale en-US # set localebash
cf config --trace true # enable API tracing (like CF_TRACE=true)
cf config --trace /tmp/cf-trace.log # trace to file
cf config --color false # disable colored output
cf config --locale en-US # set localecf oauth-token
cf oauth-token
bash
cf oauth-token # print current access token (for scripting)bash
cf oauth-token # print current access token (for scripting)Environment Variables
环境变量
| Variable | Description |
|---|---|
| Override |
| |
| |
| Docker registry password for |
| Max minutes to wait for staging (default: 15) |
| Max minutes to wait for app start (default: 5) |
| Max seconds for API connection (default: 5) |
| 变量 | 说明 |
|---|---|
| 覆盖 |
| 设为 |
| 设为 |
| 用于 |
| 等待 staging 的最大分钟数(默认:15) |
| 等待应用启动的最大分钟数(默认:5) |
| API 连接的最大秒数(默认:5) |
Plugins
插件
bash
cf plugins # list installed plugins
cf install-plugin PLUGIN # install (local path, URL, or repo name)
cf install-plugin -r CF-Community my-plugin # from registered repo
cf uninstall-plugin my-plugin
cf repo-plugins # list available plugins
cf list-plugin-repos # list registered repos
cf add-plugin-repo CF-Community https://plugins.cloudfoundry.org
cf remove-plugin-repo CF-CommunityPlugin code uses .
import "code.cloudfoundry.org/cli/v9/plugin"bash
cf plugins # list installed plugins
cf install-plugin PLUGIN # install (local path, URL, or repo name)
cf install-plugin -r CF-Community my-plugin # from registered repo
cf uninstall-plugin my-plugin
cf repo-plugins # list available plugins
cf list-plugin-repos # list registered repos
cf add-plugin-repo CF-Community https://plugins.cloudfoundry.org
cf remove-plugin-repo CF-Community插件代码使用 。
import "code.cloudfoundry.org/cli/v9/plugin"MTA / Multiapps Plugin (cf deploy
)
cf deployMTA / Multiapps 插件(cf deploy
)
cf deployCAP applications and MTA projects are deployed as archives using the CF CLI plugin. This provides the command (distinct from ).
.mtarmultiappscf deploycf pushCAP 应用和 MTA 项目通过 CF CLI 插件以 归档形式部署。该插件提供 命令(与 不同)。
multiapps.mtarcf deploycf pushInstall the plugin and build tool
安装插件和构建工具
Before running or , verify both tools are present. Run these checks and install if missing:
mbt buildcf deploybash
undefined在运行 或 之前,请确保两个工具都已安装。运行以下检查,如果缺失则安装:
mbt buildcf deploybash
undefinedCheck and install mbt (MTA Build Tool)
Check and install mbt (MTA Build Tool)
if ! command -v mbt &>/dev/null; then
echo "mbt not found — installing..."
npm install -g mbt
else
echo "mbt $(mbt --version) already installed"
fi
if ! command -v mbt &>/dev/null; then
echo "mbt not found — installing..."
npm install -g mbt
else
echo "mbt $(mbt --version) already installed"
fi
Check and install the multiapps CF CLI plugin
Check and install the multiapps CF CLI plugin
if ! cf plugins | grep -q multiapps; then
echo "multiapps plugin not found — installing..."
cf install-plugin multiapps -f
else
echo "multiapps plugin already installed"
cf plugins | grep multiapps
fi
undefinedif ! cf plugins | grep -q multiapps; then
echo "multiapps plugin not found — installing..."
cf install-plugin multiapps -f
else
echo "multiapps plugin already installed"
cf plugins | grep multiapps
fi
undefinedBuild and deploy an MTA
构建并部署 MTA
bash
undefinedbash
undefinedBuild the .mtar archive from mta.yaml
Build the .mtar archive from mta.yaml
mbt build
mbt build
Deploy the archive to the targeted CF org/space
Deploy the archive to the targeted CF org/space
cf deploy mta_archives/<app>_1.0.0.mtar
cf deploy mta_archives/<app>_1.0.0.mtar
Deploy with verbose output
Deploy with verbose output
cf deploy mta_archives/<app>_1.0.0.mtar -e config.mtaext
cf deploy mta_archives/<app>_1.0.0.mtar -e config.mtaext
Check deploy status
Check deploy status
cf mta-ops # list ongoing MTA operations
cf mta <mta-id> # show MTA status
cf mtas # list all deployed MTAs
cf undeploy <mta-id> --delete-services # remove an MTA + its services
undefinedcf mta-ops # list ongoing MTA operations
cf mta <mta-id> # show MTA status
cf mtas # list all deployed MTAs
cf undeploy <mta-id> --delete-services # remove an MTA + its services
undefinedTroubleshooting cf deploy
cf deploycf deploy
故障排查
cf deploy| Error | Cause | Fix |
|---|---|---|
| multiapps plugin not installed | |
| AI Core extended plan not entitled or org plan restricted | Check BTP entitlements; |
| Previous deploy left partial state | |
Build fails with | Node version mismatch in | Ensure |
| 错误 | 原因 | 修复 |
|---|---|---|
| multiapps 插件未安装 | |
| AI Core 的 extended 套餐未授权,或组织套餐受限 | 检查 BTP 授权;使用 CAP 与 AI Core 时需 |
| 之前的部署留下了部分状态 | 先执行 |
Build fails with | | 确保 |
Troubleshooting
故障排查
Common Issues
常见问题
| Symptom | Likely Cause | Fix |
|---|---|---|
| Token expired or not authenticated | Run |
| Missing target context | Run |
| App crashes on push | Bad start command or missing deps | Check |
| Staging fails | Wrong buildpack or missing files | Verify buildpack with |
| App takes too long to stage | Increase |
| SSL cert errors | Self-signed certs | Use |
| Route already exists | Another app/space owns the route | Use |
| Service bind fails | Service not ready or wrong space | Check |
| 症状 | 可能原因 | 修复 |
|---|---|---|
| 令牌已过期或未认证 | 重新运行 |
| 缺少目标上下文 | 运行 |
| 推送时应用崩溃 | 启动命令错误或缺少依赖 | 查看 |
| Staging 失败 | buildpack 错误或缺少文件 | 使用 |
| 应用 stage 时间过长 | 增大 |
| SSL 证书错误 | 自签名证书 | 使用 |
| 路由已存在 | 其他应用/空间占用了该路由 | 使用 |
| 服务绑定失败 | 服务未就绪或空间错误 | 检查 |
Debugging Steps
调试步骤
- Check logs: — always the first thing to try
cf logs my-app --recent - Enable tracing: — see API requests/responses
CF_TRACE=true cf push my-app - Check events: — see recent crashes, restages, scaling
cf events my-app - SSH in: — inspect the running container
cf ssh my-app - Check env: — verify
cf env my-appand user env varsVCAP_SERVICES - API debug: — inspect process-level details
cf curl /v3/apps/GUID/processes
- 检查日志: — 通常要首先尝试
cf logs my-app --recent - 启用跟踪: — 查看 API 请求/响应
CF_TRACE=true cf push my-app - 检查事件: — 查看最近的崩溃、restage、扩缩容
cf events my-app - SSH 进入: — 检查运行中的容器
cf ssh my-app - 检查环境变量: — 验证
cf env my-app和用户环境变量VCAP_SERVICES - API 调试: — 检查进程级细节
cf curl /v3/apps/GUID/processes
Verifying Command Success
验证命令是否成功
bash
cf push my-app
echo $? # 0 = success, non-zero = failurebash
cf push my-app
echo $? # 0 = success, non-zero = failureCommon Workflows
常见工作流
Deploy a Node.js app with a Postgres service
部署带 Postgres 服务的 Node.js 应用
bash
cf login -a https://api.example.com --sso
cf target -o my-org -s dev
cf create-service postgres standard my-db
cf push my-app -b nodejs_buildpack
cf bind-service my-app my-db
cf restage my-appbash
cf login -a https://api.example.com --sso
cf target -o my-org -s dev
cf create-service postgres standard my-db
cf push my-app -b nodejs_buildpack
cf bind-service my-app my-db
cf restage my-appZero-downtime deployment
零停机部署
bash
cf push my-app --strategy rollingbash
cf push my-app --strategy rollingIf something goes wrong mid-deploy:
If something goes wrong mid-deploy:
cf cancel-deployment my-app
undefinedcf cancel-deployment my-app
undefinedCI/CD pipeline pattern
CI/CD 流水线模式
bash
cf api https://api.example.com
cf auth "$CF_USERNAME" "$CF_PASSWORD"
cf target -o my-org -s production
cf push my-app -f manifest-prod.yml --strategy rolling --no-waitbash
cf api https://api.example.com
cf auth "$CF_USERNAME" "$CF_PASSWORD"
cf target -o my-org -s production
cf push my-app -f manifest-prod.yml --strategy rolling --no-waitScale based on load
根据负载扩缩容
bash
cf scale my-app -i 10 # scale out to 10 instances
cf scale my-app -m 1G # increase memory per instancebash
cf scale my-app -i 10 # scale out to 10 instances
cf scale my-app -m 1G # increase memory per instance