使用 GKE 外掛程式安裝
本頁面說明如何使用 GKE 外掛程式,在 Google Kubernetes Engine (GKE) 叢集上安裝 Config Connector。
如要進一步瞭解各個安裝選項及其優缺點,請參閱「選擇安裝類型」。
請手動安裝 Config Connector,而非使用外掛程式。此外掛程式與叢集的 GKE 子版本綁定,可能比最新 Config Connector 版本落後 12 個月以上。如果您已使用外掛程式,可以改為手動安裝。
事前準備
開始之前,請確認您已執行下列工作:
- 啟用 Google Kubernetes Engine API。 啟用 Google Kubernetes Engine API
- 如要使用 Google Cloud CLI 執行這項工作,請安裝並初始化 gcloud CLI。如果您先前已安裝 gcloud CLI,請執行
gcloud components update指令,取得最新版本。較舊的 gcloud CLI 版本可能不支援執行本文件中的指令。
選取或建立 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 的叢集上,啟用 workload identity pool 和 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 替換為 Google Cloud 專案 ID。
Google Cloud 控制台
如要使用 Google Cloud 控制台建立叢集,請執行下列步驟:
在 Google Cloud 控制台中,前往「Create a Kubernetes cluster」(建立 Kubernetes 叢集) 頁面。
在「Cluster basics」(叢集基本資訊) 區段中,指定叢集的「Name」(名稱) 和位置。
在導覽窗格中,按一下「Advanced settings」(進階設定)。
在「Workload identity」列中,按一下 edit「Edit configuration」(編輯設定),勾選「Enable Workload Identity」(啟用 Workload Identity) 核取方塊,然後按一下「Save」(儲存)。
在「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 的叢集。「Cluster Details」(叢集詳細資料) 頁面隨即顯示。
在「Features」(功能) 專區中,找到「Config Connector」列,然後按一下 「Edit」(編輯)。
勾選「Enable Config Connector」(啟用 Config Connector) 核取方塊,然後按一下「Save Changes」(儲存變更),更新叢集。
建立身分
Config Connector 會透過 Identity and Access Management (IAM) 服務帳戶進行驗證,並使用 Workload Identity Federation for GKE 將 IAM 服務帳戶與 Kubernetes 服務帳戶繫結,藉此建立及管理 Google Cloud 資源。
設定命名空間模式或叢集模式後,Config Connector 才會管理資源。在大多數情況下,您應使用命名空間模式。請按照所選模式的步驟操作:
- 如要使用命名空間模式,請略過本節和「設定 Config Connector」一節。外掛程式已安裝運算子,並在命名空間模式中建立
ConfigConnector物件。針對每個命名空間,完成「以命名空間模式安裝 Config Connector」中的步驟,然後返回「指定資源建立位置」。 - 如要使用叢集模式,請完成本節和「設定 Config Connector」一節中的步驟。每個叢集只需完成這些步驟一次。
如要建立身分,請完成下列步驟:
建立 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替換為 Google Cloud 專案 ID。
資料夾
如要在特定資料夾中建立資源,請執行下列指令:
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 版本時,就稱為對該 GKE 子版本「推出新的 Config Connector 版本」。
Google Cloud 不會將新的 Config Connector 版本,發布至舊到足以在穩定版或穩定版發布管道上使用的 GKE 子版本,以確保穩定性,除非偵測到廣泛問題的緊急情況。
如何取得最新版 Config Connector
為確保您使用的是最新版 Config Connector,建議您手動安裝 Config Connector 並升級。手動安裝可讓您直接控制版本,並在最新功能和修正項目推出時立即使用。
如要從 Config Connector 外掛程式切換至手動安裝,請按照操作說明進行。
外掛程式與叢集的 GKE 子版本綁定,可能比最新 Config Connector 版本落後 12 個月以上。雖然 Config Controller 比外掛程式更新,但與手動安裝相比,仍可能落後最新版本。
解除安裝 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「Clusters」(叢集) 頁面,選取要更新的叢集。
點選「編輯」,「編輯叢集」畫面隨即顯示。
按一下「外掛程式」。
選取「Config Connector」,然後選擇「停用」。
按一下「儲存」來更新叢集。
後續步驟
- 開始使用 Config Connector。
- 瞭解如何排解 Config Connector 問題。