【问题标题】:GCP - 使用 HPA 根据自定义日志记录指标扩展 GKE pod
【发布时间】:2021-11-26 02:13:07
【问题描述】:

我想在 GKE HPA 上使用自定义日志指标。 Metrics 可以在 metrics explorer 上查看,但无法在 HPA 上使用。我们已经安装了自定义指标适配器,并且我们能够成功使用其他自定义指标,如 kubernetes.io|pod|network|received_bytes_count 进行扩展。下图显示了我想在 HPA 上使用的自定义指标的指标资源管理器图表

此指标是根据应用程序日志创建的

使用 HPA yaml 来使用该指标

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name:   "similar-products-rts-hpa"
  namespace: relevancy
spec:
  behavior:
    scaleUp:
      stabilizationWindowSeconds: 120
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: similar-products
  minReplicas: 3
  maxReplicas: 6
  metrics:
    - type: Pods
      pods:
        metric:
          name: "logging.googleapis.com|user|Similar_Products(RTS)_Inbound_Request_Count"
        target:
          type: AverageValue
          averageValue: 25

请在下方查找错误

The HPA was unable to compute the replica count: unable to get metric logging.googleapis.com|user|Similar_Products(RTS)_Inbound_Request_Count: unable to fetch metrics from custom metrics API: googleapi: Error 400: The supplied filter does not specify a valid combination of metric and monitored resource descriptors. The query will not return any time series., badRequest

【问题讨论】:

  • 您遇到哪种类型的错误?您是否使用指标部署应用程序?你在关注文档吗?
  • 错误为 400 查询不会返回任何时间序列

标签: kubernetes google-cloud-platform google-kubernetes-engine kubernetes-pod spring-cloud-gcp


【解决方案1】:

不幸的是,upper case letters in metric names are not supported 作为 HPA 将指标视为伪资源,这意味着它们不区分大小写。我也相信括号对于指标名称也是无效字符。

您是否可以将指标名称更改为小写并删除括号?也许像similar_products_rts_inbound_request_count这样的东西?

编辑: 我刚刚注意到的另一个问题是该指标是一个容器指标,而不是一个 pod 指标。在this change 之前,需要修改自定义指标适配器部署以支持容器指标。您可以使用当前的manifest 更新您的部署,也可以通过添加--fallback-for-container-metrics=true 来修改您的当前部署:

spec:
      serviceAccountName: custom-metrics-stackdriver-adapter
      containers:
      - image: gcr.io/gke-release/custom-metrics-stackdriver-adapter:v0.12.0-gke.0
        imagePullPolicy: Always
        name: pod-custom-metrics-stackdriver-adapter
        command:
        - /adapter
        - --use-new-resource-model=true
        - --fallback-for-container-metrics=true
        resources:
          limits:
            cpu: 250m
            memory: 200Mi
          requests:
            cpu: 250m
            memory: 200Mi 

【讨论】:

  • 我可以将指标名称更改为小写是时间序列错误的原因
  • 这应该可以解决您的问题。您可能还需要从指标名称中删除括号。我更新了上面的答案。
  • HPA 无法计算副本数:无法获取指标 logging.googleapis.com|user|similarproducts_inbound_request_count:无法从自定义指标 API 中获取指标:googleapi:错误 400:提供的过滤器不会未指定指标和受监控资源描述符的有效组合。查询不会返回任何时间序列。, badRequest 仍然得到同样的错误
  • 您何时部署自定义指标适配器?
  • 几个月前
猜你喜欢
  • 2023-01-13
  • 1970-01-01
  • 2021-07-08
  • 2020-10-15
  • 2020-01-12
  • 2019-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多