使用 App Lifecycle Manager 部署 MySQL 实例

了解如何使用 App Lifecycle Manager 部署 Cloud SQL 实例。

准备工作

  1. 登录您的 Google 账号。

    如果您还没有 Google 账号,请 注册新账号

  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the App Lifecycle Manager, Artifact Registry, Infrastructure Manager, Developer Connect, Cloud Build, and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  5. Create a service account:

    1. 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.
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. 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.

    5. Click Create and continue.
    6. Grant the Project > Owner role to the service account.

      To grant the role, find the Select a role list, then select Project > Owner.

    7. Click Continue.
    8. Click Done to finish creating the service account.

  6. 安装 Google Cloud CLI。

  7. 如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI

  8. 如需初始化 gcloud CLI,请运行以下命令:

    gcloud init
  9. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  10. Verify that billing is enabled for your Google Cloud project.

  11. Enable the App Lifecycle Manager, Artifact Registry, Infrastructure Manager, Developer Connect, Cloud Build, and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  12. Create a service account:

    1. 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.
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. 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.

    5. Click Create and continue.
    6. Grant the Project > Owner role to the service account.

      To grant the role, find the Select a role list, then select Project > Owner.

    7. Click Continue.
    8. Click Done to finish creating the service account.

  13. 安装 Google Cloud CLI。

  14. 如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI

  15. 如需初始化 gcloud CLI,请运行以下命令:

    gcloud init
  16. App Lifecycle Manager 服务账号 授予所需权限:
    1. 依次前往 App Lifecycle Manager > 概览 开始使用

      前往 App Lifecycle Manager 使用入门

    2. 在显示消息 The required permissions for App Lifecycle Manager account haven't been granted 的横幅中,点击 Grant permissions (授予权限)。

使用组合模板对 Cloud SQL 产品进行建模

在本部分中,您将使用 App Lifecycle Manager 对包含 Cloud SQL 实例的组合模板 (sql-quickstart-template) 进行建模,方法是使用 App Design Center。

  1. 在 Google Cloud 控制台中,依次前往 App Lifecycle Manager > SaaS 产品

    前往 SaaS 产品

  2. 点击创建

  3. SaaS 产品名称 字段中,输入 my-sql-quickstart-saas-offering

  4. 区域 下拉列表中,选择以下区域:

    • us-central1
    • us-east1
    • us-east5

    点击确定

  5. 点击创建 。创建 my-sql-quickstart-saas-offering 可能需要几分钟时间。

    系统会打开 SaaS 产品详情 页面。

  6. SaaS 产品详情 页面上,点击创建新模板

  7. 创建新的组合模板 页面上:

    1. 模板 ID 框中,输入 sql-quickstart-template
    2. 点击创建模板 。App Lifecycle Manager 将需要几分钟时间来创建组合模板。

      App Lifecycle Manager 成功创建模板后,您会在 SaaS 产品详情 页面的已关联的应用模板 部分中看到其详细信息。

  8. 已关联的应用模板 部分中,依次前往管理模板 > 在画布中配置

    App Design Center 会在 Google Cloud 控制台窗口中打开。

  9. 组件 区域中,找到并点击 Cloud SQL (My SQL) 模板。

    系统会将 Cloud SQL (My SQL) 组件添加到画布中。

  10. 依次点击继续 > 使用 App Lifecycle Manager 进行大规模部署

    App Lifecycle Manager 会在 Google Cloud 控制台窗口中打开。

  11. 已关联的应用模板 部分中,点击更新模板修订版本

  12. 更新模板修订版本 页面上,在修订版本 下拉列表中选择 r-2

  13. 点击更新已关联的应用模板 部分会显示正在导入应用模板

    App Lifecycle Manager 可能需要几分钟时间来导入模板修订版本。修订版本导入完成后,您会在单元种类 标签页中看到填充的单元种类列表。

使用 App Lifecycle Manager 预配 Cloud SQL 实例

在本部分中,您将在 us-central1 区域中创建并预配包含 Cloud SQL 实例的单元 (my-sql-quickstart-unit)。

  1. my-sql-quickstart-saas-offeringSaaS 产品详情 页面上,点击预配

    系统会打开预配 页面。

  2. 预配 页面上,在区域 下拉列表中选择 us-central1

    点击添加 以将单元添加到您的 SaaS 产品。

  3. 添加要预配的单元 面板上:

    1. 单元名称 框中,输入 my-sql-quickstart-unit-1
    2. 单元种类 下拉列表中,选择 sql-quickstart-template 单元种类。
    3. 版本 下拉列表中,选择 (r-3)。
    4. 服务账号 下拉列表中,选择您在 准备工作部分中创建的服务帐号。
  4. 点击添加租户项目变量

    1. 选择您的项目以预配资源。
  5. 添加要预配的单元 面板的其他输入变量 部分中:

    1. 点击 sql-my-sql-1_database_version 下拉列表。

      • 变量值 框中,输入 MY_SQL_8_0

      点击完成

    2. 点击 sql-my-sql-1_name 下拉列表。

      • 变量值 框中,输入 my-sql-db-1

      点击完成

    3. 点击 sql-my-sql-1_project_id 下拉列表。

      • 变量值 框中,输入您的项目 ID。

      点击完成

    4. 点击 sql-my-sql-1_region 下拉列表。

      • 变量值 框中,输入 us-central1

      点击完成

    点击添加 。您会在要预配的单元 表格中看到 my-sql-quickstart-unit-1

  6. 点击预配 以预配 my-sql-quickstart-unit-1,这将在您的 SaaS 产品中创建一个实时 Cloud SQL 实例。

    App Lifecycle Manager 可能需要几分钟时间来预配 my-sql-quickstart-unit-1

查看已部署的 Cloud SQL 实例

您现在已使用 App Lifecycle Manager 部署 Cloud SQL 实例。

如需查看您在此快速入门中部署的 Cloud SQL 实例,请执行以下操作:

  1. 在 Google Cloud 控制台中,依次前往 App Lifecycle Manager > 单元 > 单元详情 页面。

    前往“单元”页面

  2. 点击您的单元名称:my-sql-quickstart-unit-1

  3. 单元详情 页面上:

    1. 查看状态 是否为:

      • 就绪 :如果 Cloud SQL 实例已预配。
      • 正在预配 :如果操作仍在进行中。

清理

为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。

删除项目

如果您在新 Google Cloud 项目中部署了 Cloud SQL 实例,但如果 您不再需要该项目,请完成以下步骤来将其删除:

  1. 在 Google Cloud 控制台中,前往管理资源页面。

    转到“管理资源”

  2. 在项目列表中,选择要删除的项目,然后点击删除
  3. 在提示符处,输入项目 ID,然后点击关停

后续步骤