設定控制器管理工具的速率限制

本頁說明如何為 Config Connector 中的控制器管理員設定整體速率限制 (權杖 bucket 速率限制)。

頻率限制會控管 Config Connector 對 Kubernetes API 伺服器發出的要求數。有兩種設定:

  • qps (每秒查詢次數) 設定會決定 Config Connector 可向 Kubernetes API 伺服器提出要求的平均速率。

  • burst 值允許的要求數比 qps 限制多,但僅限短期。即使在需要向 Kubernetes API 伺服器發出更多查詢時 (例如使用 GitOps 套用新批次的設定),Config Connector 也能快速調解。

您可以這樣想像頻率限制的「憑證區塊」演算法:假設有一個容量為 burst 個憑證的區塊,並以 qps 的速率重新填滿。每個要求都需要從 bucket 中取得一個權杖。如果 bucket 為空,要求會延遲,直到有權杖可用為止。

設定命名空間控制器管理員的速率限制

如果 Config Connector 設定為以命名空間模式執行,您可以使用 NamespacedControllerReconciler 自訂資源,在指定命名空間中設定 cnrm-controller-manager 控制器的 Kubernetes 用戶端速率限制。您可以在 Config Connector 1.119 以上版本中,為這個控制器設定速率限制。

  1. 建立名為 configure-rate-limit.yaml 的檔案,並將下列 YAML 複製到該檔案:

    apiVersion: customize.core.cnrm.cloud.google.com/v1beta1
    kind: NamespacedControllerReconciler
    metadata:
      name: cnrm-controller-manager # name must not contain the namespace ID suffix
      namespace: NAMESPACE
    spec:
      rateLimit:
        qps: 80 # the default value is 20
        burst: 40 # the default value is 30
    

    NAMESPACE 替換成命名空間名稱。

  2. 使用 kubectl apply 將速率限制設定套用至叢集:

    kubectl apply -f configure-rate-limit.yaml
  3. 執行下列指令,確認設定是否成功:

    kubectl get namespacedcontrollerreconciler cnrm-controller-manager -n NAMESPACE -o jsonpath='{.status.healthy}'

    輸出內容應顯示 status.healthy 欄位設為 true

  4. 執行下列指令,確認 --qps--burst 旗標已新增至控制器的管理員容器:cnrm-controller-manager

    kubectl describe statefulsets -n cnrm-system -l "cnrm.cloud.google.com/scoped-namespace=NAMESPACE"

    輸出會包含下列內容:

    Containers:
    manager:
      Image:      gcr.io/gke-release/cnrm/controller:fd4c42c
      Port:       23232/TCP
      Host Port:  0/TCP
      Command:
        /configconnector/manager
      Args:
        --qps=80
        --burst=40
        --scoped-namespace=config-control
        --prometheus-scrape-endpoint=:8888
    

在叢集模式中設定速率限制

從 1.125 版開始,如果 Config Connector 設定為叢集模式,您可以使用 ControllerReconciler 自訂資源,設定控制器 Kubernetes 用戶端的速率限制。cnrm-controller-manager用法與命名空間模式類似,但在此情況下,您應使用 ControllerReconciler CR,而非 NamespacedControllerReconciler,如下列範例所示:

apiVersion: customize.core.cnrm.cloud.google.com/v1alpha1
kind: ControllerReconciler
metadata:
  name: cnrm-controller-manager
spec:
  rateLimit:
    qps: 80 # the default value is 20
    burst: 40 # the default value is 30