使用 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, Cloud Build, Cloud Storage, Developer Connect, Infrastructure Manager, Design Center, App Hub, Cloud Resource Manager, Identity and Access Management, Cloud Asset Inventory, Cloud Monitoring, Cloud Logging, and Service Health APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    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, Cloud Build, Cloud Storage, Developer Connect, Infrastructure Manager, Design Center, App Hub, Cloud Resource Manager, Identity and Access Management, Cloud Asset Inventory, Cloud Monitoring, Cloud Logging, and Service Health APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    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. 在显示消息“尚未授予 App Lifecycle Manager 账号所需权限”的横幅中,点击授予权限

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

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

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

    前往 SaaS 产品

  2. 点击创建

  3. Name of the SaaS offering 字段中,输入: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 (MySQL) 模板。

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

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

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

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

  12. 更新模板修订版本页面上,从修订版本下拉菜单中选择 r-2

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

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

使用 App Lifecycle Manager 预配 Cloud SQL 实例

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

  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 下拉菜单。

      • 变量值框中,输入 MYSQL_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. 点击 Provision 以预配 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,然后点击关停

后续步骤