在本教學課程中,您將建立 Google Kubernetes Engine (GKE) Enterprise 版叢集,並使用 Config Sync 同步處理多重存放區範例存放區中的設定。
假設貴機構的法規遵循團隊負責確保所有人都遵守內部規則。為強制執行這些規則,法規遵循團隊已建立設定,並將其新增至範例存放區。貴機構中的每個叢集都必須與存放區同步,您有責任建立及同步叢集。
事前準備
- 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.
-
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.
-
Make sure that you have the following role or roles on the project: GKE Hub Admin
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
前往「IAM」頁面 - 選取專案。
- 按一下「授予存取權」 。
-
在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。
- 在「Select a role」(選取角色) 清單中,選取角色。
- 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
- 按一下 [Save]。
啟用 Google Kubernetes Engine (GKE) Enterprise 版 API。這對 Config Sync 來說至關重要。
在 Google Cloud 控制台中,前往「Kubernetes Engine」頁面。
按一下「add_box Create」(建立)。
在「Autopilot」部分,選取「Configure」(設定)。
在「Cluster basics」(叢集基本資訊) 專區的「Name」(名稱) 欄位中輸入
cs-cluster
。在「叢集層級」部分中,選取「Enterprise 層級」。所有其他欄位則保留建議的預設值。
按一下「建立」,系統會將您帶往「Kubernetes clusters」(Kubernetes 叢集) 頁面。叢集會在幾分鐘內建立完成。在叢集旁的「狀態」欄看到綠色勾號,就表示叢集已準備就緒。
- 前往 Google Cloud 控制台的「Features」(功能) 區段,然後點選「Config」(設定) 頁面。
- 按一下「安裝 Config Sync」add。
- 選取「自動升級」,啟用 Config Sync 自動升級版本功能。
- 在「安裝選項」下方,選取「在個別叢集上安裝 Config Sync」。
- 在「Available clusters」(可用叢集) 表格中,選取
cs-cluster
並按一下「Install Config Sync」(安裝 Config Sync)。 在「設定」分頁中,幾分鐘後,cs-cluster
的狀態應會顯示為「已啟用」。 - 在「Config Sync dashboard」(Config Sync 資訊主頁) 上,按一下「Deploy cluster package」(部署叢集套件)。
- 在「Select clusters for package deployment」(選取要部署套件的叢集) 表格中,選取
cs-cluster
,然後按一下「Continue」(繼續)。 - 保留選取的「Package hosted on Git」(Git 上託管的套件),然後按一下「Continue」(繼續)。
- 在「Package name」(套件名稱) 欄位中,輸入
sample-repository
。 - 在「Repository URL」(存放區網址) 欄位中輸入
https://github.com/GoogleCloudPlatform/anthos-config-management-samples
。 - 在「Path」(路徑) 欄位中輸入
config-sync-quickstart/multirepo/root
。 - 所有其他欄位則保留預設值。
按一下「Deploy Package」(部署套件)。
幾分鐘後,
cs-cluster
的「Sync status」(同步處理狀態) 欄中應該會顯示「Synced」(同步處理完成)。前往 Google Cloud 控制台的 GKE 選單。
按一下
cs-cluster
旁的 more_vert「動作」,然後按一下 delete「刪除」。系統提示您進行確認時,再按一下 [Delete] (刪除)。
- 瞭解如何驗證設定。
建立叢集
在本節中,您將建立可在本教學課程中使用的叢集。 雖然在實際使用情況中,您可能會管理多個叢集,但為了簡化本教學課程,您只會建立及管理一個叢集。
如要建立叢集,請完成下列步驟:
設定叢集
您已建立叢集,現在可以設定 Config Sync,將範例存放區
config-sync-quickstart
目錄中的設定同步處理至叢集。如要在 Google Cloud 控制台中設定 Config Sync,請完成下列步驟:
Config Sync 與存放區同步後,會持續使用存放區中的設定來協調叢集狀態。
查看套件詳細資料
如要查看 Config Sync 管理的所有物件,請在「Packages」(套件) 分頁中按一下
cs-cluster
,然後查看套件詳細資料頁面。您可以在這個頁面查看每個套件同步處理的所有資源總覽,以及資源類型和資源同步處理的命名空間等詳細資料。您可以前往 GitHub 存放區的 /config-sync-quickstart/multirepo/ 資料夾,探索導致系統建立這些命名空間的設定。
config-sync-quickstart
目錄包含 ClusterRole、CustomResourceDefinition、Rolebinding、Namespace 和 RepoSync 設定。此外,也包含 Prometheus 監控運算子的設定。清除所用資源
後續步驟
-