在 Google Cloud 控制台中建立管道和發布版本
本頁面說明如何使用 Google Cloud 主控台建立 Cloud Deploy 提交管道,然後為該管道建立版本。
在本快速入門導覽課程中,您將執行以下操作:
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Deploy, Cloud Build, GKE, Artifact Registry, Cloud Run, and Cloud Storage APIs.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Deploy, Cloud Build, GKE, Artifact Registry, Cloud Run, and Cloud Storage APIs.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
如果您已安裝 CLI,請確認您執行的是最新版本:
gcloud components update
建立執行階段環境
如果您要部署至 Cloud Run,可以略過這項指令。
針對 GKE,請使用預設設定建立兩個叢集:quickstart-cluster-for-console-staging
和 quickstart-cluster-for-console-prod
。叢集的 Kubernetes API 端點必須可透過公開網際網路存取。根據預設,外部可以存取 GKE 叢集。
gcloud container clusters create-auto quickstart-cluster-for-console-staging \
--project=PROJECT_ID \
--region=us-central1 && \
gcloud container clusters create-auto quickstart-cluster-for-console-prod \
--project=PROJECT_ID \
--region=us-central1
建立推送管道和兩個目標
您可以使用 Cloud Deploy,根據一或多個 YAML 檔案中指定的設定,建立發布管道和目標。不過,您也可以使用 Google Cloud 主控台建立提交管道。
在本節中,您將使用 Google Cloud 主控台建立發布管道和兩個目標。使用 Google Cloud 主控台時,您不需要建立任何 YAML 檔案;Cloud Deploy 會為您建立 skaffold.yaml 和資訊清單。
在 Google Cloud 控制台中,前往 Cloud Deploy 主頁面。
按一下 [建立]。
系統會顯示「Create a delivery pipeline」表單。
在「管道名稱」欄位中,將預設文字改為
in-console-quickstart-pipeline
。視需要輸入這個提交管道的說明。
在「Region」(區域) 下拉式選單中,選取「
us-central1
」。選取執行階段。
如果您要部署至 GKE,請選取「Google Kubernetes Engine」。否則請選取「Cloud Run」。
建立目標:
GKE
在「新目標」下方的「目標名稱」欄位中,將預設文字替換為
console-staging
。在「Kubernetes Engine 叢集」下拉式選單中,選取
quickstart-cluster-for-console-staging
。按一下 [完成]。
按一下「新增目標」。
將 目標名稱的預設文字替換為
console-prod
。從 Kubernetes Engine 叢集下拉式選單中選取
quickstart-cluster-for-console-prod
。選取「須經核准才能執行推出作業」。
在這個快速入門課程中,我們要求核准第二個目標,但不要求核准第一個目標。
按一下「建立」,即可建立這個提交管道。
Cloud Run
在「新目標」下方的「目標名稱」欄位中,將預設文字替換為
console-staging
。從「Region」下拉式選單中,選取
us-central1
。按一下 [完成]。
按一下「新增目標」。
將 目標名稱的預設文字替換為
console-prod
。為這個目標啟用「須經核准才能推出」核取方塊。
在這個快速入門課程中,我們要求核准第二個目標,但不要求核准第一個目標。
按一下「建立」,即可建立這個提交管道。
您現在擁有一個含有兩個目標的推送管道,可以開始建立發布版本。
管道頁面會顯示兩個目標,但沒有任何推出作業。
建立版本
您現在擁有一個含有兩個目標的發布管道,這些目標會指向兩個 GKE 叢集或兩個 Cloud Run 服務,因此您可以建立版本,將應用程式部署至第一個目標。
如果您尚未前往顯示新提交管道的「提交管道」頁面
in-console-quickstart-pipeline
,請立即前往該頁面。顯示管道圖表,但沒有推出作業。
按一下「Create release」按鈕。
系統會顯示「Create a release」對話方塊。大部分欄位都會預先填入資料。請保留這些預設值。
您可以按一下「View manifest」按鈕,查看任一目標的自動產生資訊清單,也可以按一下「View Skaffold file」,查看產生的
skaffold.yaml
。您也可以編輯這些值,但在本快速入門課程中,請保留這些值。您也可以在「說明」欄位中新增此版本的說明。
按一下「Create」即可開始發布。
系統會顯示推出至第一個目標的推出詳細資料頁面,您可以查看這項推出作業的進度。這項作業需要幾分鐘才能完成。這項作業可能需要幾秒鐘的時間才會開始。
第一次推出作業完成後,按一下推送管道名稱,前往推送管道頁面。
系統會顯示管道圖表,並顯示第一個目標的推播已完成。
點選「推送」,即可開始推送至下一個目標。
系統會顯示「宣傳」對話方塊。
保留預設值,視需要新增推廣說明,然後按一下「推廣」。
由於我們在建立第二個目標時選取「須經過核准才能推出」,因此這項促銷活動正在等待核准。
在推送管道圖表中,按一下「Review」。
系統會顯示核准頁面。
再次按一下「Review」,然後在核准對話方塊中按一下「Approve」。
開始為第二個目標進行推播。您可以再次按一下提交管道名稱,在管道視覺化中查看進度。
第二次發布完成後,應用程式就會部署至第二個目標,且發布管道已完成。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取您在本頁所用資源的費用,請按照下列步驟操作。
刪除 GKE 叢集或 Cloud Run 服務:
GKE
gcloud container clusters delete quickstart-cluster-for-console-staging --region=us-central1 --project=PROJECT_ID \ && gcloud container clusters delete quickstart-cluster-for-console-prod --region=us-central1 --project=PROJECT_ID
Cloud Run
gcloud run services delete in-console-quickstart-pipeline-target-1 --region=us-central1 --project=PROJECT_ID \ && gcloud run services delete in-console-quickstart-pipeline-target-2 --region=us-central1 --project=PROJECT_ID
在「發布管道」頁面中,按一下「刪除」,即可刪除發布管道、版本和推播。
在提供的欄位中輸入管線名稱,然後按一下「確認」,即可完成資源刪除作業。
刪除兩個目標:
gcloud deploy targets delete console-staging --region=us-central1 && \ gcloud deploy targets delete console-prod --region=us-central1
刪除 Cloud Deploy 建立的 Cloud Storage 值區。
一個結尾是
_clouddeploy
,另一個是[region].deploy-artifacts.[project].appspot.com
。
大功告成,您已經完成本快速入門導覽課程!