使用 App Lifecycle Manager 部署应用
借助 App Lifecycle Manager,您可以自动执行多组件应用的部署和生命周期管理,从而在 Google Cloud中预配一致的环境。在本快速入门中,您将在 Application Design Center 中使用 Cloud Run 和 Cloud Storage 为复合应用模板建模,然后预配一个实时单元。
准备工作
-
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 App Lifecycle Manager, Artifact Registry, Cloud Build, Cloud Run, Cloud Storage, Developer Connect, Infrastructure Manager, App Design Center, App Hub, Resource Manager, Identity and Access Management, Cloud Asset Inventory, Cloud Monitoring, Cloud Logging, and Service Health APIs, if any are not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart. - Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click Continue.
-
Click Done to finish creating the service account.
-
Ensure that you have the Create Service Accounts IAM role
(
- 向 App Lifecycle Manager 服务账号授予所需权限:
在 Google Cloud 控制台中,依次前往 App Lifecycle Manager > 概览 > 开始使用。
- 如果出现显示尚未授予 App Lifecycle Manager 账号所需的权限消息的横幅,请点击授予权限。
使用复合模板对产品进行建模
使用 App Lifecycle Manager 和 Application Design Center 为将 Cloud Run 服务连接到 Cloud Storage 存储桶的复合模板 (run-storage-quickstart) 建模。
配置 SaaS 产品
在 Google Cloud 控制台中,依次前往App Lifecycle Manager > SaaS 产品。
点击创建。
在 SaaS 产品名称字段中,输入
run-storage-quickstart-offering。在区域列表中,选择以下区域,然后点击确定:
us-central1us-east1us-east5
点击创建。创建
run-storage-quickstart-offering需要几分钟时间。创建 SaaS 产品后,系统会打开 SaaS 产品详情页面。
创建组合模板
- 在 SaaS 产品/服务详情页面上,点击创建新模板。
在创建新的组合模板页面上,配置模板:
- 在模板 ID 字段中,输入
run-storage-quickstart。 点击创建模板。
App Lifecycle Manager 创建完组合模板后,其详细信息会显示在 SaaS 产品/服务详情页面的关联的应用模板部分中。
- 在模板 ID 字段中,输入
在关联的应用模板部分中,点击管理模板,然后点击在画布中配置。
应用设计中心会在 Google Cloud 控制台中打开。
在组件区域中,将以下组件添加到设计画布:
- 点击 Cloud Run(服务),向画布添加
cloud-run-1组件。 - 点击 Cloud Storage,将
cloud-storage-1组件添加到画布。
- 点击 Cloud Run(服务),向画布添加
在画布上,从 cloud-run-1 组件拖动到 cloud-storage-1 组件以创建连接。
连接组件会将 Cloud Run 服务账号传递给 Cloud Storage 存储桶的 IAM 绑定,并为其分配
roles/storage.objectAdmin角色。在画布上,点击 cloud-run-1 组件以打开配置面板:
- 在容器区域中,展开容器 1。
- 在容器映像字段中,输入公开示例容器映像
us-docker.pkg.dev/cloudrun/container/hello:latest。 - 点击保存。
依次点击继续 > 使用 App Lifecycle Manager 进行大规模部署。
App Lifecycle Manager 会在 Google Cloud 控制台中打开。
在关联的应用模板部分中,点击更新模板修订版本。
在更新模板修订版本页面上,在修订版本列表中选择
r-2,然后点击更新。已关联的应用模板部分会显示正在导入应用模板。导入完成后,单元种类标签页会列出生成的
u-native-components单元种类。
使用 App Lifecycle Manager 预配应用
在
run-storage-quickstart-offering的 SaaS 产品详情页面上,点击预配。预配页面随即打开。
在预配页面上,在区域列表中选择
us-central1,然后点击添加。在添加要预配的单元面板中,配置单元:
- 在单元名称字段中,输入
run-storage-quickstart-unit-1。 - 在单位种类列表中,选择
u-native-components单位种类。 - 在版本列表中,选择为模板修订版本生成的版本。
- 在服务账号列表中,选择您在准备工作部分中创建的执行服务账号。
- 在单元名称字段中,输入
点击添加租户项目变量,然后选择将用于预配资源的项目。
在其他输入变量区域中,点击添加输入变量,然后输入以下组件输入变量的值:
- 名称:
cloud-run-1_project_id,变量类型:String,变量值:您的项目 ID - 名称:
cloud-run-1_location,变量类型:String,变量值:us-central1 - 名称:
cloud-run-1_service_name,变量类型:String,变量值:quickstart-web - 名称:
cloud-storage-1_project_id,变量类型:String,变量值:您的项目 ID - 名称:
cloud-storage-1_location,变量类型:String,变量值:us-central1 - 名称:
cloud-storage-1_name,变量类型:String,变量值:全球唯一的存储桶名称,例如PROJECT_ID-quickstart-bkt
- 名称:
点击添加。
run-storage-quickstart-unit-1单元会显示在要预配的单元数量表中。点击预配以部署
run-storage-quickstart-unit-1。Cloud Run 服务和 Cloud Storage 会在几分钟后预配。
如需在其他区域中预配更多单元,请从区域列表中选择相应区域,然后点击添加。
查看已部署的单元
验证 App Lifecycle Manager 是否已预配您的单元及其资源。
在 Google Cloud 控制台中,前往App Lifecycle Manager > 单元页面。
点击
run-storage-quickstart-unit-1打开单元详情页面。在单元详情页面上,查看状态字段:
- 就绪:Cloud Run 服务和 Cloud Storage 存储桶已预配。
- 正在预配:部署操作仍在进行中。
清理
为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。
删除项目
如果您在新的 Google Cloud 项目中部署了应用资源,但不再需要该项目,请完成以下步骤来将其删除:
- 在 Google Cloud 控制台中,前往管理资源页面。
- 在项目列表中,选择要删除的项目,然后点击删除。
- 在提示符处,输入项目 ID,然后点击关停。
后续步骤
- 如需导入和部署自定义 Terraform 组件,请参阅设计和部署 SaaS 产品教程。
- 如需详细了解 App Lifecycle Manager,请参阅 App Lifecycle Manager 概览。
- 如需开始使用 App Lifecycle Manager,请先创建 SaaS 产品。
- 如需了解如何使用服务账号以及如何为这些账号授予所需权限,请参阅 App Lifecycle Manager 服务账号。
- 如需了解更新版本的步骤,请参阅更新 SaaS 产品。