使用 App Lifecycle Manager 部署 MySQL 執行個體

瞭解如何使用 App Lifecycle Manager 部署 Cloud SQL 執行個體。

事前準備

  1. 登入 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」

    2. 在顯示「尚未授予 App Lifecycle Manager 帳戶的必要權限」訊息的橫幅中,按一下「授予權限」

使用複合範本為 Cloud SQL 產品建立模型

在本節中,您將使用 App Lifecycle Manager 建立複合範本 (sql-quickstart-template) 模型,其中包含使用 App Design Center 的 Cloud SQL 執行個體。

  1. 在 Google Cloud 控制台中,依序前往「App Lifecycle Manager」 >「SaaS Offering」

    前往 SaaS 產品

  2. 點選「建立」

  3. 在「SaaS 產品名稱」欄位中輸入:my-sql-quickstart-saas-offering

  4. 在「區域」下拉式選單中選取區域:

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

    按一下 [確定]。

  5. 點按「Create」(建立)。建立 my-sql-quickstart-saas-offering 可能需要幾分鐘。

    「SaaS 產品詳細資料」頁面隨即開啟。

  6. 在「SaaS 產品詳細資料」頁面中,按一下「建立新範本」

  7. 在「Create a new composite template」(建立新的複合範本) 頁面中:

    1. 在「Template ID」(範本 ID) 方塊中輸入 sql-quickstart-template
    2. 按一下「建立範本」,App Lifecycle Manager 需要幾分鐘才能建立複合範本。

      App Lifecycle Manager 成功建立範本後,您會在「SaaS 產品詳細資料」頁面的「已連結的應用程式範本」部分看到範本詳細資料。

  8. 在「已連結的應用程式範本」部分,依序前往「管理範本」 >「在畫布中設定」

    App Design Center 會在 Google Cloud 控制台視窗中開啟。

  9. 在「Components」區域中,找出並點選「Cloud SQL (My SQL)」範本。

    畫布上會新增 Cloud SQL (MySQL) 元件。

  10. 依序點選「繼續」 >「透過 App Lifecycle Manager 大規模部署」

    應用程式生命週期管理工具會在 Google Cloud 控制台視窗中開啟。

  11. 在「Connected application template」(已連結的應用程式範本) 部分,按一下「Update template revision」(更新範本修訂版本)

  12. 在「更新範本修訂版本」頁面,選取「修訂版本」下拉式選單中的 r-2

  13. 按一下 Update (更新)。「已連結的應用程式範本」部分會顯示「正在匯入應用程式範本」

    App Lifecycle Manager 可能需要幾分鐘的時間才能匯入範本修訂版本。修訂版本匯入完成後,「Unit kinds」(單元類型) 分頁中就會顯示單元類型清單。

使用 App Lifecycle Manager 佈建 Cloud SQL 執行個體

在本節中,您將在 us-central1 區域中建立及佈建含有 Cloud SQL 執行個體的單元 (my-sql-quickstart-unit)。

  1. my-sql-quickstart-saas-offering 的「SaaS 產品詳細資料」頁面中,按一下「佈建」

    系統會開啟「佈建」頁面。

  2. 在「Provision」(佈建) 頁面,選取「Region」(區域) 下拉式選單中的「us-central1

    按一下「新增」,將單元新增至 SaaS 產品。

  3. 在「新增要佈建的單元」面板中:

    1. 在「Unit name」(單位名稱) 方塊中輸入 my-sql-quickstart-unit-1
    2. 在「單元種類」下拉式選單中,選取 sql-quickstart-template 單元種類。
    3. 在「版本」下拉式選單中,選取「(r-3)」。
    4. 在「Service account」(服務帳戶) 下拉式選單中,選取您在「事前準備」一節中建立的服務帳戶。
  4. 按一下「新增租戶專案變數」

    1. 選取專案來佈建資源。
  5. 在「Add unit to provision」(新增要佈建的單元)面板的「Other input variables」(其他輸入變數) 區段中:

    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

      按一下 [完成]

    按一下「Add」(新增)。您會在「Units to be provisioned」(要佈建的裝置) 表格中看到 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」(應用程式生命週期管理工具) >「Units」(單元) >「Unit details」(單元詳細資料) 頁面。

    前往「單位」

  2. 按一下機構單位名稱:my-sql-quickstart-unit-1

  3. 在「單元詳細資料」頁面中:

    1. 確認「狀態」為:

      • 如果已佈建 Cloud SQL 執行個體,則為「就緒」
      • 如果作業仍在進行中,則為「佈建中」

清除所用資源

為了避免系統向您的 Google Cloud 帳戶收取本頁面所用資源的費用,請按照下列步驟操作。

刪除專案

如果您是在新 Google Cloud 專案中部署 Cloud SQL 執行個體,且現在不再需要該專案,請完成下列步驟來刪除專案:

  1. 前往 Google Cloud 控制台的「Manage resources」(管理資源) 頁面。

    前往「Manage resources」(管理資源)

  2. 從專案清單中選取要刪除的專案,然後點選「Delete」(刪除)
  3. 收到提示時,請輸入專案 ID,然後點選「Shut down」(關閉)

後續步驟