本教學課程說明如何透過 gcloud
指令列工具使用 Deployment Manager。請按照以下設定步驟,將本機環境備妥以使用 Deployment Manager。
建立專案
Deployment Manager 需要 Google Cloud 專案。如果您已有專案,則可以使用現有的專案。
如果您是第一次使用 Google Cloud,可以建立新專案並利用 Google Cloud免費試用方案;該方案提供您 $300 美元的額度,可在 90 天內使用所有的 Google Cloud 產品。如要申請免費試用方案,請參閱以下步驟:
- 開啟Google Cloud 控制台。
- 按照說明申請免費試用版。
- 系統提示您建立專案時,請輸入用於識別專案的名稱和專案 ID,或是接受預設值,再按一下「建立」。
為您要管理的 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
現在您已設定環境,可以開始建立部署作業了。