設定控制器管理員頻率限制


本頁面說明如何在 Config Connector 中為控制器管理員設定整體速率限制 (符記桶速率限制)。

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

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

  • burst 值可在短時間內允許超過 qps 限制的要求。這有助於 Config Connector 快速進行調和,即使在需要向 Kubernetes API 伺服器提出更多查詢的情況下也一樣,例如在使用 GitOps 套用新一批設定時。

您可以將「符記桶」演算法視為頻率限制,如下所示:假設有一個容量為 burst 符記的桶,以 qps 的頻率重新填滿。每個要求都需要一個來自區塊的符記。如果值區為空白,要求會延遲,直到權杖可用為止。

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

如果 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 自訂資源設定 cnrm-controller-manager 控制器的 Kubernetes 用戶端的速率限制。使用方式與命名空間模式類似,但在這種情況下,您應使用 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