使用 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 外掛程式
您可以透過建立新的 GKE 叢集,或在現有叢集中啟用 Config Connector 外掛程式,安裝 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 叢集的名稱。
- 支援GKE 發布版本的 CHANNEL、
rapid
和regular
。 - 將 PROJECT_ID 改成您的 Google Cloud 專案 ID。
Google Cloud 控制台
如要使用 Google Cloud 控制台建立叢集,請執行下列步驟:
造訪 Google Cloud 控制台的 Google Kubernetes Engine 選單。
按一下「建立」,系統會顯示「Create a Kubernetes cluster」(建立 Kubernetes 叢集) 頁面。
指定叢集的「名稱」。
選擇支援的主版本。
視需要設定叢集的其他部分。
在導覽窗格的「Cluster」(叢集) 下方,按一下「Security」(安全性)。
勾選「Enable Workload Identity」(啟用 Workload Identity) 核取方塊。
在左側導覽窗格的「Cluster」(叢集) 底下,按一下「Features」(功能)。
勾選「Enable Config Connector」(啟用 Config Connector) 核取方塊。
按一下 [建立]。
建立叢集後,請參閱「設定 IAM 政策」一文。
在現有叢集上啟用設定連接器外掛程式
您可以使用 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」(叢集詳細資料) 頁面隨即顯示。
在「功能」部分下方,找出「設定連接器」列,然後按一下
「編輯」。勾選「Enable Config Connector」(啟用設定連接器) 核取方塊,然後按一下「Save Changes」(儲存變更) 更新叢集。
設定 IAM 政策以連線至 Google Cloud API
如要讓 Config Connector 使用 GKE 適用的工作負載身分聯盟管理您的 Google Cloud 資源,請建立 IAM 政策。
如要設定政策繫結,請建立 IAM 允許政策,參照在叢集中安裝 Config Connector 時自動建立的 Kubernetes 服務帳戶:
gcloud projects add-iam-policy-binding projects/PROJECT_ID \
--role=roles/iam.workloadIdentityUser \
--member=principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/NAMESPACE/sa/cnrm-system/cnrm-controller-manager \
--condition=None
更改下列內容:
PROJECT_ID
:您的 Google Cloud 專案 ID。PROJECT_NUMBER
:您的數字 Google Cloud專案編號。NAMESPACE
:Config Connector 服務帳戶的 Kubernetes 命名空間名稱。如果您未明確建立命名空間,這個值會是default
。
設定 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 # 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
-
使用
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 子版本,因此有兩種情況會導致 Google Cloud自動升級叢集的 Config Connector 外掛程式:
叢集會升級至新的 GKE 子版本,並對應至較新的 Config Connector 版本。
叢集使用的是 GKE 子版本,該版本相當新,不會出現在一般或穩定版發布管道中,且Google Cloud 會將該 GKE 子版本重新對應至新的 Config Connector 版本。
當 Google Cloud 重新對應 GKE 子版本,並將現有叢集升級至新版 Config Connector 時,就會在該 GKE 子版本中「推出新版 Config Connector」。
Google Cloud 不會將新的 Config Connector 版本推送至已過舊,可在 Regular 或 Stable 發布管道版本中使用的 GKE 次要版本,除非在偵測到廣泛問題的緊急情況下。
如何取得最新的 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
停用設定檔連接器外掛程式,請執行下列指令:gcloud container clusters update CLUSTER_NAME --update-addons ConfigConnector=DISABLED
將 CLUSTER_NAME 替換為已安裝 Config Connector 外掛程式的叢集名稱。
Cloud 控制台
如要透過 Google Cloud 控制台停用 Config Connector 外掛程式,請執行下列步驟。
前往 Google Cloud 控制台的「Google Kubernetes Engine 叢集」頁面,然後選取要更新的叢集。
按一下「編輯」。畫面上會顯示「Edit clusters」(編輯叢集) 畫面。
按一下「外掛程式」。
選取「Config Connector」,然後選擇「Disabled」。
按一下「儲存」即可更新叢集。
後續步驟
- 開始使用 Config Connector。
- 瞭解如何排解 Config Connector 的問題。