Loading...
Loading...
Compare original and translation side by side
Scaffolded project? Use thecommands throughout this guide — they wrap Terraform, Docker, and deployment into a tested pipeline.makeNo scaffold? See Quick Deploy below, or the ADK deployment docs. For production infrastructure, scaffold with./adk-scaffold
references/cloud-run.mdagent-engine.mdterraform-patterns.mdevent-driven.mdfast_api_app.pyObservability: See the adk-observability-guide skill for Cloud Trace, prompt-response logging, BigQuery Analytics, and third-party integrations.
references/cloud-run.mdagent-engine.mdterraform-patterns.mdevent-driven.mdfast_api_app.py可观测性: 有关Cloud Trace、提示响应日志、BigQuery分析及第三方集成的内容,请查看adk-observability-guide技能文档。
| Criteria | Agent Engine | Cloud Run | GKE |
|---|---|---|---|
| Languages | Python | Python | Python (+ others via custom containers) |
| Scaling | Managed auto-scaling (configurable min/max, concurrency) | Fully configurable (min/max instances, concurrency, CPU allocation) | Full Kubernetes scaling (HPA, VPA, node auto-provisioning) |
| Networking | VPC-SC and PSC supported | Full VPC support, direct VPC egress, IAP, ingress rules | Full Kubernetes networking |
| Session state | Native | In-memory (dev), Cloud SQL, or Agent Engine session backend | Custom (any Kubernetes-compatible store) |
| Batch/event processing | Not supported | | Custom (Kubernetes Jobs, Pub/Sub) |
| Cost model | vCPU-hours + memory-hours (not billed when idle) | Per-instance-second + min instance costs | Node pool costs (always-on or auto-provisioned) |
| Setup complexity | Lower (managed, purpose-built for agents) | Medium (Dockerfile, Terraform, networking) | Higher (Kubernetes expertise required) |
| Best for | Managed infrastructure, minimal ops | Custom infra, event-driven workloads | Full control, open models, GPU workloads |
| 评估标准 | Agent Engine | Cloud Run | GKE |
|---|---|---|---|
| 支持语言 | Python | Python | Python(通过自定义容器支持其他语言) |
| 缩放能力 | 托管式自动缩放(可配置最小/最大实例数、并发数) | 完全可配置(最小/最大实例数、并发数、CPU分配) | 完整的Kubernetes缩放能力(HPA、VPA、节点自动配置) |
| 网络配置 | 支持VPC-SC和PSC | 完整VPC支持、直接VPC出口、IAP、入口规则 | 完整Kubernetes网络能力 |
| 会话状态 | 原生 | 内存存储(开发环境)、Cloud SQL或Agent Engine会话后端 | 自定义存储(任何兼容Kubernetes的存储系统) |
| 批量/事件处理 | 不支持 | 提供 | 自定义处理(Kubernetes Jobs、Pub/Sub) |
| 成本模型 | vCPU小时 + 内存小时(空闲时不收费) | 按实例秒计费 + 最小实例成本 | 节点池成本(始终运行或自动配置) |
| 设置复杂度 | 较低(托管式,专为agent打造) | 中等(需配置Dockerfile、Terraform、网络) | 较高(需要Kubernetes专业知识) |
| 最佳适用场景 | 托管式基础设施、最小化运维工作 | 自定义基础设施、事件驱动型工作负载 | 完全控制、开源模型、GPU工作负载 |
undefinedundefined
All commands support `--with_ui` to deploy the ADK dev UI. Cloud Run also accepts extra `gcloud` flags after `--` (e.g., `-- --no-allow-unauthenticated`).
See `adk deploy --help` or the [ADK deployment docs](https://google.github.io/adk-docs/deploy/) for full flag reference.
> For CI/CD, observability, or production infrastructure, scaffold with `/adk-scaffold` and use the sections below.
---
所有命令都支持`--with_ui`参数以部署ADK开发UI。Cloud Run还支持在`--`后添加额外的`gcloud`标志(例如:`-- --no-allow-unauthenticated`)。
如需完整的参数参考,请查看`adk deploy --help`或[ADK部署文档](https://google.github.io/adk-docs/deploy/)。
> 若要实现CI/CD、可观测性或搭建生产环境基础设施,请使用`/adk-scaffold`生成脚手架并参考以下章节。
---make setup-dev-envterraform applydeployment/terraform/dev/app_sadeployment/terraform/dev/make deploygcloud run deploy --source .make setup-dev-envNote:doesn't automatically use the Terraform-createdmake deploy. Passapp_saexplicitly or update the Makefile.--service-account
make setup-dev-envdeployment/terraform/dev/terraform applyapp_sadeployment/terraform/dev/make deploygcloud run deploy --source .make setup-dev-env注意:不会自动使用Terraform创建的make deploy。请显式传递app_sa参数或更新Makefile。--service-account
make deploymake deploymake deploymake deploy/adk-scaffolduvx agent-starter-pack enhance . --cicd-runner github_actions -y -sgh auth login # (skip if already authenticated)uvx agent-starter-pack setup-cicd \
--staging-project YOUR_STAGING_PROJECT \
--prod-project YOUR_PROD_PROJECT \
--repository-name YOUR_REPO_NAME \
--repository-owner YOUR_GITHUB_USERNAME \
--auto-approve \
--create-repository/adk-scaffolduvx agent-starter-pack enhance . --cicd-runner github_actions -y -sgh auth login # (已登录可跳过)uvx agent-starter-pack setup-cicd \
--staging-project YOUR_STAGING_PROJECT \
--prod-project YOUR_PROD_PROJECT \
--repository-name YOUR_REPO_NAME \
--repository-owner YOUR_GITHUB_USERNAME \
--auto-approve \
--create-repositorysetup-cicd| Flag | Description |
|---|---|
| GCP project ID for staging environment |
| GCP project ID for production environment |
| GitHub repository name and owner |
| Skip Terraform plan confirmation prompts |
| Create the GitHub repo if it doesn't exist |
| Separate GCP project for CI/CD infrastructure. Defaults to prod project |
| Store Terraform state locally instead of in GCS (see |
uvx agent-starter-pack setup-cicd --help| 参数 | 描述 |
|---|---|
| 预发布环境的GCP项目ID |
| 生产环境的GCP项目ID |
| GitHub仓库名称和所有者 |
| 跳过Terraform计划确认提示 |
| 如果仓库不存在则创建GitHub仓库 |
| 用于CI/CD基础设施的独立GCP项目。默认使用生产环境项目 |
| 将Terraform状态存储在本地而非GCS中(请查看 |
uvx agent-starter-pack setup-cicd --help| Runner | Pros | Cons |
|---|---|---|
| github_actions (Default) | No PAT needed, uses | Requires GitHub CLI authentication |
| google_cloud_build | Native GCP integration | Requires interactive browser authorization (or PAT + app installation ID for programmatic mode) |
| 运行器 | 优势 | 劣势 |
|---|---|---|
| github_actions(默认) | 无需PAT,使用 | 需要GitHub CLI认证 |
| google_cloud_build | 原生GCP集成 | 需要交互式浏览器授权(或使用PAT + 应用安装ID以实现程序化授权) |
cicd_runner_sasetup-cicdterraform applycicd_runner_saterraform applymainPath filter: Staging CD uses— it only triggers when files underpaths: ['app/**']change. The first push afterapp/won't trigger staging CD unless you modify something insetup-cicd. If nothing happens after pushing, this is why.app/
workflow_runApproving: Go to GitHub Actions → the production workflow run → click "Review deployments" → approve the pendingenvironment. This is GitHub's environment protection rules, not a custom mechanism.production
setup-cicdgit add . && git commit -m "Initial agent implementation"
git push origin mainundefinedmain路径过滤: 预发布环境CD使用——仅当paths: ['app/**']目录下的文件变更时才会触发。执行setup-cicd后的第一次推送不会触发预发布环境CD,除非你修改了app/目录下的内容。如果推送后没有任何反应,原因就在这里。app/
workflow_run批准方式: 进入GitHub Actions → 生产环境工作流运行记录 → 点击“Review deployments” → 批准待处理的环境。这是GitHub的环境保护规则,而非自定义机制。production
setup-cicdgit add . && git commit -m "Initial agent implementation"
git push origin mainundefined
---
---references/cloud-run.mdhttps://google.github.io/adk-docs/deploy/cloud-run/index.mdreferences/cloud-run.mdhttps://google.github.io/adk-docs/deploy/cloud-run/index.mddeploy.pyAdkAppNoCLI exists for Agent Engine. Deploy viagcloudordeploy.py. Query via the Pythonadk deploy agent_engineSDK.vertexai.Client
make deploydeployment_metadata.jsonreferences/agent-engine.mdhttps://google.github.io/adk-docs/deploy/agent-engine/index.mddeploy.pyAdkApp目前没有针对Agent Engine的CLI。 请通过gcloud或deploy.py进行部署。通过Pythonadk deploy agent_engineSDK进行查询。vertexai.Client
make deploydeployment_metadata.jsonreferences/agent-engine.mdhttps://google.github.io/adk-docs/deploy/agent-engine/index.mdapp_sadeployment/terraform/iam.tfcicd_runner_sadeployment/terraform/iam.tfcicd_runner_saiam.serviceAccountUserapp_saapp_sasecretmanager.secretAccessorapp_sadeployment/terraform/iam.tfcicd_runner_sadeployment/terraform/iam.tfcicd_runner_saapp_saiam.serviceAccountUserapp_sasecretmanager.secretAccessorundefinedundefined
**Grant access:** For Cloud Run, grant `secretmanager.secretAccessor` to `app_sa`. For Agent Engine, grant it to the platform-managed SA (`service-PROJECT_NUMBER@gcp-sa-aiplatform-re.iam.gserviceaccount.com`).
**Pass secrets at deploy time (Agent Engine):**
```bash
make deploy SECRETS="API_KEY=my-api-key,DB_PASS=db-password:2"ENV_VAR=SECRET_IDENV_VAR=SECRET_ID:VERSIONos.environ.get("API_KEY")
**授予访问权限:** 对于Cloud Run,请为`app_sa`授予`secretmanager.secretAccessor`角色。对于Agent Engine,请为平台托管的SA(`service-PROJECT_NUMBER@gcp-sa-aiplatform-re.iam.gserviceaccount.com`)授予该角色。
**部署时传递密钥(Agent Engine):**
```bash
make deploy SECRETS="API_KEY=my-api-key,DB_PASS=db-password:2"ENV_VAR=SECRET_IDENV_VAR=SECRET_ID:VERSIONos.environ.get("API_KEY")jupyter notebook notebooks/adk_app_testing.ipynbimport json
import vertexai
with open("deployment_metadata.json") as f:
engine_id = json.load(f)["remote_agent_engine_id"]
client = vertexai.Client(location="us-central1")
agent = client.agent_engines.get(name=engine_id)
async for event in agent.async_stream_query(message="Hello!", user_id="test"):
print(event)make playgroundjupyter notebook notebooks/adk_app_testing.ipynbimport json
import vertexai
with open("deployment_metadata.json") as f:
engine_id = json.load(f)["remote_agent_engine_id"]
client = vertexai.Client(location="us-central1")
agent = client.agent_engines.get(name=engine_id)
async for event in agent.async_stream_query(message="Hello!", user_id="test"):
print(event)make playgroundAuth required by default. Cloud Run deploys with, so all requests need an--no-allow-unauthenticatedheader with an identity token. Getting a 403? You're likely missing this header. To allow public access, redeploy withAuthorization: Bearer.--allow-unauthenticated
SERVICE_URL="https://SERVICE_NAME-PROJECT_NUMBER.REGION.run.app"
AUTH="Authorization: Bearer $(gcloud auth print-identity-token)"默认需要认证。 Cloud Run默认使用部署,因此所有请求都需要带有身份令牌的--no-allow-unauthenticated头。如果收到403错误,很可能是缺少该头。如需允许公共访问,请重新部署并添加Authorization: Bearer参数。--allow-unauthenticated
SERVICE_URL="https://SERVICE_NAME-PROJECT_NUMBER.REGION.run.app"
AUTH="Authorization: Bearer $(gcloud auth print-identity-token)"
> **Common mistake:** Using `{"message": "Hello!", "user_id": "...", "session_id": "..."}` returns `422 Field required`. The ADK HTTP server expects the `new_message` / `parts` schema shown above, and the session must already exist.
> **常见错误:** 使用`{"message": "Hello!", "user_id": "...", "session_id": "..."}`会返回`422 Field required`。ADK HTTP服务器需要上述`new_message` / `parts`格式的请求体,且会话必须已存在。make load-testtests/load_test/README.mdmake load-testtests/load_test/README.mdundefinedundefined
IAP (Identity-Aware Proxy) secures the Cloud Run service — only authorized Google accounts can access it. After deploying, grant user access via the [Cloud Console IAP settings](https://cloud.google.com/run/docs/securing/identity-aware-proxy-cloud-run#manage_user_or_group_access).
For Agent Engine with a custom frontend, use a **decoupled deployment** — deploy the frontend separately to Cloud Run or Cloud Storage, connecting to the Agent Engine backend API.
---
IAP(身份感知代理)会保护Cloud Run服务——只有授权的Google账号才能访问。部署完成后,请通过[Cloud Console IAP设置](https://cloud.google.com/run/docs/securing/identity-aware-proxy-cloud-run#manage_user_or_group_access)授予用户访问权限。
对于带有自定义前端的Agent Engine,请使用**解耦部署**——将前端单独部署到Cloud Run或Cloud Storage,连接到Agent Engine后端API。
---maingcloud run revisions list --service=SERVICE_NAME --region=REGION
gcloud run services update-traffic SERVICE_NAME \
--to-revisions=REVISION_NAME=100 --region=REGIONmake deploymaingcloud run revisions list --service=SERVICE_NAME --region=REGION
gcloud run services update-traffic SERVICE_NAME \
--to-revisions=REVISION_NAME=100 --region=REGIONmake deployreferences/terraform-patterns.mdreferences/terraform-patterns.md| Issue | Solution |
|---|---|
| Terraform state locked | |
| GitHub Actions auth failed | Re-run |
| Cloud Build authorization pending | Use |
| Resource already exists | |
| Agent Engine deploy timeout / hangs | Deployments take 5-10 min; check if engine was created (see Agent Engine Specifics) |
| Secret not available | Verify |
| 403 on deploy | Check |
| 403 when testing Cloud Run | Default is |
| Cold starts too slow | Set |
| Cloud Run 503 errors | Check resource limits (memory/CPU), increase |
| 403 right after granting IAM role | IAM propagation is not instant — wait a couple of minutes before retrying. Don't keep re-granting the same role |
| Resource seems missing but Terraform created it | Run |
| 问题 | 解决方案 |
|---|---|
| Terraform状态被锁定 | 在deployment/terraform/目录下执行 |
| GitHub Actions认证失败 | 重新在CI/CD terraform目录下运行 |
| Cloud Build授权待处理 | 改用 |
| 资源已存在 | 使用 |
| Agent Engine部署超时/挂起 | 部署需要5-10分钟;检查引擎是否已创建(请查看Agent Engine专属配置章节) |
| 密钥不可用 | 确认 |
| 部署时出现403错误 | 检查 |
| 测试Cloud Run时出现403错误 | 默认设置为 |
| 冷启动过慢 | 在Cloud Run Terraform配置中设置 |
| Cloud Run出现503错误 | 检查资源限制(内存/CPU)、增加 |
| 授予IAM角色后立即出现403错误 | IAM权限传播并非即时生效——请等待几分钟后重试。请勿重复授予相同角色 |
| Terraform显示已创建资源,但实际找不到 | 运行 |