建立具有設定依附元件的應用程式
在本快速入門中,您會根據範例應用程式設定應用程式的依附元件,然後分別部署應用程式的各個部分。
事前準備
- 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]
部署模組
- 開啟「Command Palette」(指令面板) (
Ctrl
/Cmd
+Shift
+P
),然後執行「Cloud Code: Run on Kubernetes」(Cloud Code:在 Kubernetes 上執行)。 - 按一下「選取模組」。
選擇要部署的模組,然後按一下「確定」。
如果您按一下「db」,系統會建構「db」設定和「setup」設定。
系統提示時,請選擇映像檔登錄檔,然後按下
Enter
。
正在清除所用資源
終止應用程式後,系統會自動刪除執行期間部署的所有 Kubernetes 資源。
如要避免系統針對您在本快速入門導覽課程中所用的其他資源,向您的帳戶收取相關費用,請務必刪除您建立的叢集和專案。
如果您使用 Google Cloud ,且只想刪除叢集,請按照下列步驟操作:
- 按一下
「Cloud Code」,然後展開「Kubernetes」探索工具。
- 將指標懸停在叢集名稱上,然後按一下「open_in_new」open_in_new「在控制台中開啟」 Google Cloud 。
- 按一下「Delete」(刪除),然後點選「Delete」(刪除)。
如要刪除專案 (和相關聯的資源,包括任何叢集),請按照下列步驟操作:
前往 Google Cloud 控制台的「Projects」(專案) 頁面:
選取您在本快速入門導覽課程所建立的專案,然後按一下「Delete」(刪除)。
輸入專案 ID 確認,然後點選「Shut down」(關閉)。
接著,系統就會關閉專案並排定刪除時間。
後續步驟
- 進一步瞭解 Skaffold 模組。
- 瞭解 Cloud Code 的語言專屬偵錯支援。
- 設定,打造專屬 Cloud Code 體驗。