Config Connector 的最佳做法
本頁面說明使用 Config Connector 時應考量的最佳做法。
管理 API 配額限制
如果您遇到表示已超出 API 配額限制的錯誤,可能是因為您在同一個配額專案下建立了太多同類型的 Config Connector 資源。建立大量資源時,這些資源可能會因為 Config Connector 使用的重整策略,產生太多相同 API 端點的 API 要求。
解決這個問題的方法之一,是要求提高配額。除了增加配額之外,如果您已確認 GET 要求針對 Config Connector 資源管理的 Google Cloud 資源而導致配額錯誤,建議您考慮下列任一做法:
增加對帳間隔
您可以增加 Config Connector 比對資源之間的時間,以免觸及 API 配額。建議您將協調間隔設為 1 小時。
如要增加對帳間隔,請按照「設定對帳間隔」中的步驟操作。
將資源分割成多個專案
這種做法可將 Config Connector 資源分散到不同的專案中。在新增資源時,這個方法很實用,但如果要分割現有資源,則可能會造成風險,因為您必須刪除現有資源,並在不同專案中重新建立。刪除資源可能會導致某些類型的資源資料遺失,例如 SpannerInstance
或 BigtableTable
資源。請先備份資料,再刪除資料。
如要將現有的 Config Connector 資源分割為不同的專案,請完成下列步驟:
- 決定要將哪些 Config Connector 資源遷移至其他專案。
- 刪除 Config Connector 資源。確認
cnrm.cloud.google.com/deletion-policy
註解未設為abandon
。 - 更新您打算移至新專案的 Config Connector 資源 YAML 設定檔中的
spec.projectRef
欄位或cnrm.cloud.google.com/project-id
註解。 - 授予 Config Connector 使用的 IAM 服務帳戶新專案的適當權限。
- 套用更新的 YAML 設定,建立 Config Connector 資源。
切換至命名空間模式
您可以將不同Google Cloud 專案擁有的不同 IAM 服務帳戶繫結至 Config Connector 以命名空間模式安裝的不同命名空間,並將資源分割成不同的命名空間。如要達成這項目標,請完成下列步驟:
設定 Config Connector 以命名空間模式執行。根據操作說明,為每個專案建立新的 IAM 服務帳戶,並將這些帳戶繫結至不同的命名空間。
將適當的權限授予包含資源的專案,以便新 IAM 服務帳戶存取這些資源。
決定要將哪些 Config Connector 資源移至不同的命名空間。
更新 Config Connector 資源的 YAML 設定,並設定
cnrm.cloud.google.com/deletion-policy
註解abandon
。套用更新的 YAML 設定,以更新 Config Connector 資源的刪除政策。
更新您打算移至不同命名空間的 Config Connector 資源 YAML 設定檔中的
metadata.namespace
欄位。套用更新的 YAML 設定,取得已放棄的資源。
管理 GKE 叢集中的節點集區
在 Config Connector 中套用 ContainerCluster
資源,然後嘗試套用更新版 ContainerCluster
設定來更新 nodeConfig
或其他節點相關欄位時,您可能會遇到錯誤。這些錯誤是由於無法變更的欄位 (例如 nodeConfig
、nodeConfig.labels
、nodeConfig.taint
),這是基礎 Google Cloud API 的技術限制。
如果您需要更新這些欄位,可以使用 ContainerNodePool
資源來管理這些欄位不可變更的節點叢集。如要使用 ContainerNodePool
資源管理節點叢集,您必須指定註解 cnrm.cloud.google.com/remove-default-node-pool: "true"
。這個註解會移除在建立叢集期間建立的預設節點集區。接著,如要建立個別的節點集區,請在 ContainerNodePool
中指定 nodeConfig
欄位,而不是在 ContainerCluster
中指定。請參閱 ContainerNodePool
資源範例。
您應為 ContainerCluster
和 ContainerNodePool
資源都設定註解 cnrm.cloud.google.com/state-into-spec: absent
。這項註解可避免 Config Connector 控制器與底層 API 互動時,發生可能的調和錯誤。
以下範例顯示 ContainerCluster
和 ContainerNodePool
設定,並設定這些註解:
apiVersion: container.cnrm.cloud.google.com/v1beta1 kind: ContainerCluster metadata: name: containercluster-sample annotations: cnrm.cloud.google.com/remove-default-node-pool: "true" cnrm.cloud.google.com/state-into-spec: absent spec: description: A sample cluster. location: us-west1 initialNodeCount: 1
apiVersion: container.cnrm.cloud.google.com/v1beta1 kind: ContainerNodePool metadata: labels: label-one: "value-one" name: containernodepool-sample annotations: cnrm.cloud.google.com/state-into-spec: absent spec: location: us-west1 autoscaling: minNodeCount: 1 maxNodeCount: 3 nodeConfig: machineType: n1-standard-1 preemptible: false oauthScopes: - "https://www.googleapis.com/auth/logging.write" - "https://www.googleapis.com/auth/monitoring" clusterRef: name: containercluster-sample