Config Connector 最佳做法

本頁說明使用 Config Connector 時應注意的最佳做法。

管理 API 配額限制

如果發生錯誤,指出您已超出 API 配額限制,可能是因為您在同一個配額專案下,建立了太多相同類型的 Config Connector 資源。建立大量資源時,由於 Config Connector 採用的協調策略,這些資源可能會對同一個 API 端點產生過多的 API 要求。

其中一個解決方法是要求提高配額。除了增加配額,如果您已確認配額錯誤是因對 Config Connector 資源管理的 Google Cloud 資源發出 GET 要求所致,不妨考慮下列其中一個選項:

增加對帳間隔

您可以增加 Config Connector 調解資源的時間間隔,避免達到 API 配額上限。建議將對帳間隔設為 1 小時。

如要增加對帳間隔,請按照「設定對帳間隔」中的步驟操作。

將資源分割成多個專案

這種做法會將 Config Connector 資源分散到不同專案。這個方法很適合新增資源,但如果想分割現有資源,可能會很冒險,因為您必須刪除現有資源,並在不同專案下重新建立資源。刪除資源可能會導致資料遺失,例如 SpannerInstanceBigtableTable 資源。建議您先備份資料,再刪除資料。

如要將現有的 Config Connector 資源分割到不同專案,請完成下列步驟:

  1. 決定要將哪些 Config Connector 資源移至其他專案。
  2. 刪除 Config Connector 資源。 確認 cnrm.cloud.google.com/deletion-policy 註解未設為 abandon
  3. 在您打算移至新專案的 Config Connector 資源 YAML 設定中,更新 spec.projectRef 欄位或 cnrm.cloud.google.com/project-id 註解。
  4. 在新的專案中,授予 Config Connector 使用的 IAM 服務帳戶適當權限。
  5. 套用更新後的 YAML 設定,建立 Config Connector 資源

切換至命名空間模式

Google CloudGoogle Cloud

您可以將不同Google Cloud 專案擁有的不同 IAM 服務帳戶,繫結至以命名空間模式安裝 Config Connector 的不同命名空間,並將資源分割至不同命名空間。如要達成這個目標,請完成下列步驟:

  1. 設定 Config Connector,使其以命名空間模式執行。 從不同專案建立新的 IAM 服務帳戶,然後按照為每個專案設定 Config Connector 的操作說明,將這些帳戶繫結至不同命名空間。

  2. 將適當權限授予包含資源的專案。

  3. 決定要將哪些 Config Connector 資源移至其他命名空間。

  4. 更新 Config Connector 資源的 YAML 設定,並設定 cnrm.cloud.google.com/deletion-policy 註解 abandon

  5. 套用更新後的 YAML 設定,更新 Config Connector 資源的刪除政策。

  6. 捨棄 Config Connector 資源

  7. 在您打算移至不同命名空間的 Config Connector 資源 YAML 設定中,更新 metadata.namespace 欄位。

  8. 套用更新後的 YAML 設定,取得遭捨棄的資源

管理 GKE 叢集中的節點集區

透過套用 Config Connector 中的 ContainerCluster 資源建立叢集後,如果嘗試套用更新後的 ContainerCluster 設定,更新 nodeConfig 或其他節點相關欄位,可能會發生錯誤。這些錯誤是由於不可變更的欄位 (例如 nodeConfignodeConfig.labelsnodeConfig.taint) 所致,這是基礎 Google Cloud API 的技術限制。

如要更新這些欄位,可以使用 ContainerNodePool 資源管理節點集區,這些欄位並非不可變更。如要使用 ContainerNodePool 資源管理節點集區,請指定註解 cnrm.cloud.google.com/remove-default-node-pool: "true"。這項註解會移除叢集建立期間建立的預設節點集區。然後,如要建立個別節點集區,請在 ContainerNodePool 中指定 nodeConfig 欄位,而非 ContainerCluster。請參閱ContainerNodePool 資源範例

您應為 ContainerClusterContainerNodePool 資源設定 cnrm.cloud.google.com/state-into-spec: absent 註解。在 Config Connector 控制器與基礎 API 互動時,這項註解可避免潛在的協調錯誤。

以下範例顯示設定這些註解的 ContainerClusterContainerNodePool 設定:

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