Kubernetes Horizo​​ntal Pod Autoscaler 因意外的 GroupVersion 而失败

Kubernetes Horizontal Pod Autoscaler fails with unexpected GroupVersion

我正在尝试使用 Prometeus 和 Prometeus Adapter 创建 HPA。

我在状态中收到“意外的 GroupVersion”错误,我只是不知道它是什么意思。

$ kubectl describe hpa
Name:                                             pathology-uploader-hpa
Namespace:                                        default
Labels:                                           <none>
Annotations:                                      <none>
CreationTimestamp:                                Tue, 08 Mar 2022 15:50:12 +0000
Reference:                                        Deployment/pathology-uploader-dep
Metrics:                                          ( current / target )
  "pathology_uploader_avg_process_time" on pods:  <unknown> / 180k
Min replicas:                                     1
Max replicas:                                     100
Deployment pods:                                  0 current / 0 desired
Conditions:
  Type         Status  Reason          Message
  ----         ------  ------          -------
  AbleToScale  False   FailedGetScale  the HPA controller was unable to get the target's current scale: unexpected GroupVersion string: /apps/v1
Events:
  Type     Reason          Age                   From                       Message
  ----     ------          ----                  ----                       -------
  Warning  FailedGetScale  4m34s (x41 over 14m)  horizontal-pod-autoscaler  unexpected GroupVersion string: /apps/v1

这是我的规格:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: pathology-uploader-hpa
spec:
  maxReplicas: 100 # define max replica count
  minReplicas: 1   # define min replica count
  scaleTargetRef:
    kind: Deployment
    name: pathology-uploader-dep
    apiVersion: /apps/v1
  metrics:
    - type: Pods
      pods:
        metric:
          name: pathology_uploader_avg_process_time
        target:
          type: AverageValue
          averageValue: 180000  # allow one job to take 3 minutes

我正在使用普罗米修斯社区提供的 helm 图表。我提供给普罗米修斯适配器的规则部分是

rules:
  default: true
  custom:
  - seriesQuery: '{__name__=~"^pathology_uploader_process_time$"}'
    resources:
      template: <<.Resource>>
    name:
      matches: ".*"
      as: "pathology_uploader_avg_process_time"
    metricsQuery: <<.Series>>
prometheus:
  url: http://prometheus-server.default.svc
  port: 80
  path: ""

像下面这样更新您的规范。

"/apps/v1" 到 "apps/v1"

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: pathology-uploader-hpa
spec:
  maxReplicas: 100 # define max replica count
  minReplicas: 1   # define min replica count
  scaleTargetRef:
    kind: Deployment
    name: pathology-uploader-dep
    ## update "/apps/v1" to "apps/v1"
    apiVersion: apps/v1