使用 Cloud Code for IntelliJ 部署 Cloud Run 服务
本页面介绍如何开始使用 Cloud Code。
您将使用示例应用设置在 Cloud Run 上运行的 Hello World 服务,将服务部署到 Cloud Run,并查看实时服务资源的状态。
准备工作
- 登录您的 Google Cloud 账号。如果您是新手 Google Cloud, 请创建一个账号来评估我们的产品在 实际场景中的表现。新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Run API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Run API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.- 安装 Git,以便 Cloud Code 可以执行 Git 操作,例如克隆 示例。
- 如果您尚未安装 Cloud Code 插件 ,请进行安装。
创建 Service
Cloud Code 附带一系列 代码示例 模板,可帮助您快速入门。如需使用现有示例创建新服务,请执行以下操作:
- 在 IDE 中,打开 File > New Project ,然后选择 Cloud Code: Cloud Run 。
- 选择示例应用的编程语言,然后点击 Next。
为项目命名,然后点击 Finish。
Cloud Code 会克隆示例应用,打开新创建的项目以供使用,并创建必要的 Cloud Run 运行配置。
如果您选择了 Java 示例应用,请在出现提示时点击 Load Maven project。

您现在可以运行 Hello World 服务。Cloud Code 还会监控您的文件系统是否有更改,以便您可以近乎实时地修改并重新运行服务。
将服务部署到 Cloud Run
如需部署您的服务,请按以下步骤操作:
- 从导航栏的“运行/调试配置”选择器中选择自动创建的运行配置 Cloud Run:部署 (Cloud Run: Deploy)。
- 点击
运行。系统将显示“修改配置”窗口。 - 设置项目 ID。 Google Cloud
为您的部署平台选择一个区域。
本快速入门使用默认平台选项 Cloud Run(全代管式)作为部署平台。
点击运行。
通过输出窗口中显示的网址,查看运行中的服务。
您还可以访问输出窗口中显示的日志网址,以查看服务的状态(指标、修订版本详细信息等)。
查看资源状态
要查看正在运行的服务的资源的状态,请按以下步骤操作:
导航到 Cloud Run Explorer。您可以通过右侧的边栏面板进行访问。

如需显示服务或修订版本的属性,请在资源管理器中点击服务或修订版本。

如需查看修订版本的日志,请右键点击修订版本,然后点击查看云日志。

清理
如果您为本快速入门创建了项目,请务必将其删除,以免产生不必要的费用:
前往 Google Cloud 控制台中的“项目”页面:
选择您为本快速入门创建的项目,然后点击删除。
这将关闭该项目并安排将其删除。
如果您使用的是现有项目,并希望删除您为本快速入门创建的资源,请以下说明操作:
- 容器映像:虽然 Cloud Run 不会对未在使用中的服务计费,但您仍可能需要支付将容器映像存储在 Artifact Registry 中而产生的相关费用。如需删除映像,请按照 删除映像中的步骤执行操作。
- Cloud Run 服务 :如需删除 Cloud Run 服务,请在 控制台中使用导航菜单导航到 Cloud Run Google Cloud 。选择要删除的服务,然后点击删除 。
清理
为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。
后续步骤
- 将 Google Cloud API 和客户端库添加到项目中。
- 使用高级设置自定义您的运行配置。
- 尝试创建并 使用 Cloud Code 运行 Kubernetes 应用。