本教學課程說明如何透過 gcloud 指令列工具使用 Deployment Manager。請按照以下設定步驟,將本機環境備妥以使用 Deployment Manager。
建立專案
-
前往 Google Cloud 控制台的專案選擇器頁面。
-
選取或建立 Google Cloud 專案。
選取或建立專案所需的角色
- 選取專案:選取專案時,不需要具備特定 IAM 角色,只要您已獲授角色,即可選取任何專案。
-
建立專案:如要建立專案,您需要具備專案建立者角色 (
roles/resourcemanager.projectCreator),其中包含resourcemanager.projects.create權限。瞭解如何授予角色。
為要管理的 Google Cloud 資源啟用 API
Deployment Manager 會使用其他 Google Cloud 服務的 API 來建立和管理資源。您必須先為專案啟用服務的 API 才能建立這些資源。
您為本逐步操作說明部署了 Compute Engine 資源,因此您必須啟用 Compute Engine API。
接下來,請啟用 Deployment Manager:
安裝 Google Cloud CLI
Google Cloud CLI 具有指令列工具 gcloud,可以輕鬆地與 Deployment Manager 進行互動。
如要安裝 gcloud CLI,請按照下列步驟操作:
-
您也可以使用已預先安裝
gcloud的 Cloud Shell。 設定專案 ID。
每個指令都會要求提供專案 ID,因此設定預設專案 ID 就不必每次都必須提供。請記得將
myproject替換為您自己的專案 ID。gcloud config set project myproject設定預設區域和地區。某些 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
現在您已設定環境,可以開始建立部署作業了。