使用 GKE 外掛程式安裝
本頁說明如何使用 Config Connector 外掛程式,在 Google Kubernetes Engine (GKE) 叢集上安裝 Config Connector。
如要瞭解各個安裝選項的優缺點,請參閱「選擇安裝類型」。
事前準備
開始之前,請確認您已完成下列工作:
- 啟用 Google Kubernetes Engine API。 啟用 Google Kubernetes Engine API
- 如要使用 Google Cloud CLI 執行這項工作,請安裝並初始化 gcloud CLI。如果您先前已安裝 gcloud CLI,請執行
gcloud components update
,取得最新版本。
選取或建立 Google Cloud 專案,以便在其中安裝 Config Connector。
如果先前曾手動安裝 Config Connector,請先解除安裝,再安裝 Config Connector 外掛程式:
安裝 Config Connector 外掛程式
如要使用 Config Connector 外掛程式,請建立新的 GKE 叢集,或在現有叢集上啟用該外掛程式。安裝 Config Connector 外掛程式後,請使用 Google 服務帳戶和命名空間設定 Config Connector 安裝作業。
需求條件
Config Connector 外掛程式必須符合下列規定:
您必須使用下列 GKE 版本:
- 1.15.11-gke.5 以上版本
- 1.16.8-gke.8 以上版本
- 1.17.4-gke.5 以上版本
您必須在啟用 Config Connector 的叢集上,啟用工作負載身分集區和 Kubernetes Engine Monitoring。
設定 GKE 叢集
您可以在新叢集或現有叢集上使用 Config Connector 外掛程式。
建立啟用 Config Connector 外掛程式的新叢集
您可以使用 gcloud CLI 或Google Cloud 控制台建立 GKE 叢集。
gcloud
如要使用 Google Cloud CLI 建立叢集,請執行下列指令:
gcloud container clusters create CLUSTER_NAME \
--release-channel CHANNEL \
--addons ConfigConnector \
--workload-pool=PROJECT_ID.svc.id.goog \
--logging=SYSTEM \
--monitoring=SYSTEM
更改下列內容:
- 將 CLUSTER_NAME 替換為 GKE 叢集的名稱。
- CHANNEL,並使用 GKE 發布版本,
rapid
和regular
均支援此功能。 - 將 PROJECT_ID 改成您的專案 ID。 Google Cloud
Google Cloud 控制台
如要使用 Google Cloud 控制台建立叢集,請執行下列步驟:
前往 Google Cloud 控制台的 Google Kubernetes Engine 選單。
按一下「建立」,「建立 Kubernetes 叢集」頁面隨即顯示。
指定叢集的「名稱」。
選擇支援的主版本。
視需要設定叢集的其餘部分。
在導覽窗格的「Cluster」(叢集) 底下,按一下「Security」(安全性)。
勾選「Enable Workload Identity」(啟用 Workload Identity) 核取方塊。
在左側導覽窗格的「叢集」下方,按一下「功能」。
選取「啟用 Config Connector」核取方塊。
點選「建立」。
建立叢集後,請繼續建立身分。
在現有叢集上啟用 Config Connector 外掛程式
您可以使用 gcloud
或 Google Cloud 控制台,在現有 GKE 叢集上啟用 Config Connector 外掛程式。
必要條件
如要在現有叢集上啟用 Config Connector 外掛程式,必須符合下列先決條件:
- 您需要符合 Config Connector 外掛程式需求的叢集。
在要安裝 Config Connector 的叢集上,設定 Workload Identity Federation for GKE。
如要為節點集區啟用 Workload Identity Federation for GKE,請使用 gcloud
指令列工具:
gcloud container node-pools update NODE_POOL \
--workload-metadata=GKE_METADATA \
--cluster CLUSTER_NAME
更改下列內容:
- NODE_POOL 替換為節點集區的名稱
- CLUSTER_NAME 改成叢集名稱
啟用 Config Connector 外掛程式
您可以使用 Google Cloud CLI 或 Google Cloud 控制台,在現有的 GKE 叢集中啟用 Config Connector 外掛程式。
gcloud
如要在現有 GKE 叢集中啟用 Config Connector 外掛程式,請使用 Google Cloud CLI:
gcloud container clusters update CLUSTER_NAME \
--update-addons ConfigConnector=ENABLED
將 CLUSTER_NAME 替換為您的 GKE 叢集名稱。
Google Cloud 控制台
前往 Google Cloud 控制台的 Google Kubernetes Engine 選單。
選取要安裝 Config Connector 的叢集。「叢集詳細資料」頁面隨即顯示。
在「功能」部分下方,找到 Config Connector 列,然後按一下「編輯」
。選取「Enable Config Connector」(啟用 Config Connector) 核取方塊,然後按一下「Save Changes」(儲存變更),更新叢集。
建立身分
Config Connector 會透過身分與存取權管理 (IAM) 服務帳戶進行驗證,並使用 GKE 的工作負載身分聯合,將 IAM 服務帳戶與 Kubernetes 服務帳戶繫結,藉此建立及管理 Google Cloud 資源。
如要建立身分,請完成下列步驟:
建立 IAM 服務帳戶。如要使用現有的服務帳戶,請使用該帳戶並略過這個步驟:
gcloud iam service-accounts create SERVICE_ACCOUNT_NAME
將 SERVICE_ACCOUNT_NAME 換成服務帳戶的名稱。
如要進一步瞭解如何建立服務帳戶,請參閱「建立及管理服務帳戶」。
授予 IAM 服務帳戶專案的提升權限:
gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" \ --role="roles/editor"
將 PROJECT_ID 替換為您的專案 ID。
在 IAM 服務帳戶與 Config Connector 執行的預先定義 Kubernetes 服務帳戶之間,建立 IAM 政策繫結:
gcloud iam service-accounts add-iam-policy-binding \ SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com \ --member="serviceAccount:PROJECT_ID.svc.id.goog[cnrm-system/cnrm-controller-manager]" \ --role="roles/iam.workloadIdentityUser"
設定 Config Connector
如要完成安裝,請為 ConfigConnector
CustomResource 建立設定檔,然後使用 kubectl apply
指令套用該設定檔。Config Connector Operator 會在叢集中安裝Google Cloud 資源 CRD 和 Config Connector 元件。
如要將運算子設定為叢集模式,請完成下列步驟:
-
將下列 YAML 檔案複製到名為
configconnector.yaml
的檔案: 取代下列項目:# configconnector.yaml apiVersion: core.cnrm.cloud.google.com/v1beta1 kind: ConfigConnector metadata: # the name is restricted to ensure that there is only one # ConfigConnector resource installed in your cluster name: configconnector.core.cnrm.cloud.google.com spec: mode: cluster googleServiceAccount: "SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" # Setting `stateIntoSpec` to `Absent` is recommended. It means setting `cnrm.cloud.google.com/state-into-spec` # annotation to `absent` for all Config Connector resources created in the cluster in the future. # It prevents Config Connector from populating unspecified fields into the spec. stateIntoSpec: Absent
SERVICE_ACCOUNT_NAME
改為服務帳戶名稱。PROJECT_ID
為您的專案 ID。
-
使用
kubectl apply
將設定套用至叢集:kubectl apply -f configconnector.yaml
指定資源的建立位置
Config Connector 可依專案、資料夾或機構整理資源,與使用 Google Cloud整理資源的方式相同。
使用 Config Connector 建立資源前,您必須先設定資源的建立位置。為判斷資源的建立位置,Config Connector 會使用資源設定或現有命名空間的註解。詳情請參閱「整理資源」。
如果沒有這類用途的命名空間,請使用kubectl
建立命名空間。
kubectl create namespace NAMESPACE
將 NAMESPACE
替換為命名空間名稱。例如 config-connector
。
選取分頁,選擇要讓 Config Connector 建立資源的位置。
專案
如要在特定專案中建立資源,請執行下列指令:
kubectl annotate namespace \ NAMESPACE cnrm.cloud.google.com/project-id=PROJECT_ID
取代下列項目:
NAMESPACE
替換為您的命名空間名稱。- 將
PROJECT_ID
改成您的專案 ID。 Google Cloud
資料夾
如要在特定資料夾中建立資源,請執行下列指令:
kubectl annotate namespace \ NAMESPACE cnrm.cloud.google.com/folder-id=FOLDER_ID
取代下列項目:
NAMESPACE
替換為您的命名空間名稱。- 將
FOLDER_ID
改成您的 Google Cloud 資料夾 ID。
機構
如要在特定機構中建立資源,請執行下列指令:
kubectl annotate namespace \ NAMESPACE cnrm.cloud.google.com/organization-id=ORGANIZATION_ID
取代下列項目:
NAMESPACE
替換為您的命名空間名稱。- 將
ORGANIZATION_ID
改成您的 Google Cloud 機構 ID。
為命名空間加上註解時,Config Connector 會在對應的專案、資料夾或機構中建立資源。如要進一步瞭解 Config Connector 如何使用 Kubernetes 命名空間,請參閱「Kubernetes 命名空間和專案 Google Cloud 」。
驗證安裝
Config Connector 會在名為 cnrm-system
的命名空間中執行所有元件。如要確認 Pod 是否已準備就緒,請執行下列指令:
kubectl wait -n cnrm-system \
--for=condition=Ready pod --all
如果 Config Connector 安裝正確,輸出內容會類似以下內容:
pod/cnrm-controller-manager-0 condition met
升級 Config Connector
叢集 Config Connector 外掛程式的升級作業由 Google Cloud管理。
升級時,叢集中的資源會保留下來。
請參閱這篇文章 Google Cloud ,瞭解如何管理 Config Connector 外掛程式升級,或直接跳到如何取得最新版 Config Connector。
如何 Google Cloud 管理 Config Connector 外掛程式升級
GKE 叢集取得的 Config Connector 版本完全取決於叢集的 GKE 次要版本。例如:
GKE 子版本 | Config Connector 版本 |
---|---|
1.20 | 1.69.0 |
1.21 | 1.69.0 |
1.22 | 1.71.0 |
1.23 | 1.82.0 |
1.24 | 1.89.0 |
當版本符合資格時, Google Cloud 會將最新的 GKE 次要版本重新對應至新發布的 Config Connector 版本。對於新到無法在一般或穩定發布管道中使用的所有 GKE 次要版本,系統都會執行這項作業。
由於叢集取得的 Config Connector 版本取決於叢集的 GKE 子版本,因此在下列兩種情況下,叢集的 Config Connector 外掛程式會由 Google Cloud自動升級:
叢集會升級至新的 GKE 子版本,該版本對應至較新的 Config Connector 版本。
叢集使用的 GKE 子版本夠新,無法透過一般或穩定版發布管道取得,且Google Cloud 將該 GKE 子版本重新對應至新的 Config Connector 版本。
當 Google Cloud 重新對應 GKE 次要版本,並將現有叢集升級至新的 Config Connector 版本時,即表示「推出新的 Config Connector 版本」至該 GKE 次要版本。
Google Cloud 不會將新的 Config Connector 版本推出至舊版 GKE 次要版本,因為這些版本已在 Regular 或 Stable 發布管道中提供,基於穩定性考量,除非偵測到普遍問題等緊急情況,否則不會推出新版本。
如何取得最新版 Config Connector
透過 Config Connector 外掛程式安裝的 Config Connector 版本,通常會落後 12 個月以上。如需最新版 Config Connector,建議改用 Config Controller,或手動安裝 Config Connector 並自行升級。各選項的遷移說明如下:
如要改用 Config Controller,請按照 Config Controller 遷移操作說明,將現有的 Config Connector 資源遷移至 Config Controller 執行個體。
如要手動安裝 Config Connector,請按照操作說明,從 Config Connector 外掛程式切換至手動安裝。
解除安裝 Config Connector
如要解除安裝 Config Connector,請完成下列步驟:
使用
kubectl delete
移除 Config Connector CRD 和控制器元件:kubectl delete ConfigConnector configconnector.core.cnrm.cloud.google.com --wait=true
使用 gcloud CLI 或 Google Cloud 控制台,在叢集中停用 Config Connector 外掛程式:
gcloud
如要使用
gcloud
停用 Config Connector 外掛程式,請執行下列指令:gcloud container clusters update CLUSTER_NAME --update-addons ConfigConnector=DISABLED
將 CLUSTER_NAME 換成已安裝 Config Connector 外掛程式的叢集名稱。
Cloud 控制台
如要透過 Google Cloud 控制台停用 Config Connector 外掛程式,請按照下列步驟操作。
前往 Google Cloud 控制台的 Google Kubernetes Engine 叢集頁面,然後選取要更新的叢集。
按一下「編輯」。系統會顯示「編輯叢集」畫面。
按一下「外掛程式」。
選取「Config Connector」,然後選擇「已停用」。
按一下「儲存」即可更新叢集。
後續步驟
- 開始使用 Config Connector。
- 瞭解如何排解 Config Connector 問題。