簡體   English   中英

Kubernetes HPA 使用來自另一個部署的指標

[英]Kubernetes HPA using metrics from another deployment

我目前正在嘗試使用 prometheus 和 prometheus 適配器運行自動縮放演示,我想知道是否有一種方法可以根據 prometheus 從另一個部署中抓取的指標來自動縮放我的一個部署。

我現在擁有的是 2 個不同的部署,kafka-consumer-application(我想要擴展)和 kafka-exporter(它公開了我將用於擴展的 kafka 指標)。 我知道,如果我將它們都作為容器在同一個部署中,則自動縮放可以工作,但問題是 kafka-exporter 也會自動縮放並且它並不理想,所以我想將它們分開。 我嘗試使用以下 HPA,但無法正常工作:

kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta1
metadata:
  name: consumer-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: kafka-consumer-application
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: object
    object:
      target: kafka-exporter
      metricName: "kafka_consumergroup_lag"
      targetValue: 5

我不確定我是否做錯了什么,或者這不是我能做的,所以任何建議都值得贊賞。

謝謝!

注意:我使用此配置運行適配器:

rules:
  default: false
  resource: {}
  custom:
    - seriesQuery: 'kafka_consumergroup_lag'
      resources:
        overrides:
          kubernetes_namespace: {resource: "namespace"}
          kubernetes_pod_name: {resource: "pod"}
      name:
       matches: "kafka_consumergroup_lag"
       as: "kafka_consumergroup_lag"
      metricsQuery: 'avg_over_time(kafka_consumergroup_lag{topic="my-topic",consumergroup="we-consume"}[1m])'
``

kubernetes 文檔中,您可以閱讀:

Autoscaling on metrics not related to Kubernetes objects Applications running on Kubernetes may need to autoscale based on metrics that don't have an obvious relationship to any object in the Kubernetes cluster, such as metrics describing a hosted service with no direct correlation to Kubernetes namespaces. 在 Kubernetes 1.10 及更高版本中,您可以使用外部指標解決此用例

因此,使用外部指標,您的 HPA yaml 可能如下所示:

kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta2
metadata:
  name: consumer-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: kafka-consumer-application
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: External
    external:
      metric:
        name: kafka_consumergroup_lag
        #selector:
        #  matchLabels:
        #    topic: "my-topic"
      target:
        type: AverageValue
        averageValue: 5

如果您有多個 kafka-exporter,則可以使用selector對其進行過濾( 來源):

選擇器是給定指標的標准 kubernetes label 選擇器的字符串編碼形式 設置后,它作為附加參數傳遞給指標服務器以獲取更具體的指標范圍。 未設置時,僅 metricName 將用於收集指標

也看看這個 Stack question

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM