安裝和設定

本教學課程說明如何透過 gcloud 指令列工具使用 Deployment Manager。請按照以下設定步驟,將本機環境備妥以使用 Deployment Manager。

建立專案

  1. In the Google Cloud console, go to the project selector page.

    Go to project selector

  2. 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.

為要管理的 Google Cloud 資源啟用 API

Deployment Manager 會使用其他 Google Cloud 服務的 API 來建立和管理資源。您必須先為專案啟用服務的 API 才能建立這些資源。

您為本逐步操作說明部署了 Compute Engine 資源,因此您必須啟用 Compute Engine API。

啟用 Compute Engine API

接下來,請啟用 Deployment Manager:

啟用 Deployment Manager API

安裝 Google Cloud CLI

Google Cloud CLI 具有指令列工具 gcloud,可以輕鬆地與 Deployment Manager 進行互動。

如要安裝 gcloud CLI,請按照下列步驟操作:

  1. 下載並驗證 gcloud

    您也可以使用已預先安裝 gcloudCloud Shell

  2. 設定專案 ID。

    每個指令都會要求提供專案 ID,因此設定預設專案 ID 就不必每次都必須提供。請記得將 myproject 替換為您自己的專案 ID

    gcloud config set project myproject
    
  3. 設定預設區域和地區。某些 Google Cloud 資源會要求提供區域或地區,因此您可以設定預設區域或地區,與預設專案類似。如要設定預設區域或地區,請使用 gcloud config set。在本例中,地區請使用 us-central1,區域則使用 us-central1-f

    gcloud config set compute/region us-central1
    gcloud config set compute/zone us-central1-f
    

複製 Deployment Manager GitHub 存放區

Deployment Manager GitHub 存放區包含 Google 和 Deployment Manager 社群建立的範例,包括本逐步操作說明中使用的範例。

git clone https://github.com/GoogleCloudPlatform/deploymentmanager-samples

# open the samples folder
cd deploymentmanager-samples/examples/v2/step_by_step_guide

現在您已設定環境,可以開始建立部署作業了。