0

我想在 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
4

1 回答 1

1

不幸的是,不支持指标名称中的大写字母,因为 HPA 将指标视为伪资源,这意味着它们不区分大小写。我也相信括号对于指标名称也是无效字符。

您是否有机会将指标名称更改为小写并删除括号?也许像similar_products_rts_inbound_request_count什么?

编辑:我刚刚注意到的另一个问题是该指标是容器指标而不是 pod 指标。在此更改之前,有必要修改自定义指标适配器部署以支持容器指标。您可以使用当前清单更新部署,也可以通过添加以下内容来修改当前部署--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 
于 2021-10-06T08:21:34.157 回答