建立含有設定依附元件的應用程式
在本快速入門課程中,您將設定具有設定依附元件的應用程式 (以範例應用程式為依據),然後分別部署應用程式的各個部分。
事前準備
- 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 Google Kubernetes Engine API.
-
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 Google Kubernetes Engine API.
- 安裝 Git。您必須使用 Git,才能將範例複製到電腦。
- 如果尚未安裝 Cloud Code 外掛程式,請先安裝。
建立應用程式
複製 Bank of Anthos 存放區:
- 在頂端選單列中,依序點選「Terminal」 >「New Terminal」。
複製 Bank of Anthos 存放區:
git clone https://github.com/GoogleCloudPlatform/bank-of-anthos.git
如要開啟以 Bank of Anthos 為基礎的工作區,請在 VS Code 中依序點選「File」 >「Open folder」,然後前往複製存放區的資料夾。
按兩下
skaffold.yaml
檔案。此檔案包含多個設定,並以 YAML 文件分隔符號 (
---
) 分隔。每個設定都可以分別部署或做為依附元件參照。--- apiVersion: skaffold/v2beta18 kind: Config
指定名稱的設定稱為 Skaffold 模組。以下摘錄定義
frontend
模組。metadata: name: frontend # module defining frontend service
您可以使用
configs
標記指定設定之間的依附元件。必須先部署必要設定,才能部署目前設定。範例顯示在同一個檔案中定義的依附元件。configs
標記也可以參照目前專案中的其他skaffold.yaml
檔案。requires: - configs: [db]
部署模組
- 開啟指令面板 (
Ctrl
/Cmd
+Shift
+P
),然後執行「Cloud Code: Run on Kubernetes」(Cloud Code:在 Kubernetes 上執行)。 - 按一下「選取模組」。
選擇要部署的模組,然後按一下「OK」。
如果您按一下「db」,系統會建構 db 設定和所需的 setup 設定。
系統提示時,請選擇圖像註冊資料庫,然後按下
Enter
。
正在清除所用資源
終止應用程式後,系統會自動刪除執行期間部署的所有 Kubernetes 資源。
如要避免系統針對您在本快速入門中所用其他資源向您的帳戶收費,請務必刪除您建立的叢集和專案。
如果您使用的是 Google Cloud ,且只想刪除叢集,請按照下列步驟操作:
- 按一下
「Cloud Code」,然後展開「Kubernetes」探索工具。
- 將游標懸停在叢集���稱上,���後按一下「open_in_new」open_in_new。
- 按一下「Delete」(刪除),然後點選「Delete」(刪除)。
如要刪除專案 (以及相關聯的資源,包括任何叢集),請按照下列步驟操作:
前往 Google Cloud 控制台的「Projects」(專案) 頁面:
選取您為本快速入門導覽課程建立的專案,然後按一下「Delete」。
輸入專案 ID 以確認,然後按一下「Shut down」。
接著,系統就會關閉專案並排定刪除時間。
後續步驟
- 進一步瞭解 Skaffold 模組。
- 瞭解 Cloud Code 中特定語言的偵錯支援。
- 設定,自訂 Cloud Code 體驗。