You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

HPA无法读取Google托管Prometheus指标问题求助

问题:Google托管Prometheus指标无法被HPA读取

我们将应用指标导出至Google托管Prometheus,尽管能在Google Monitoring中查看该指标,但HPA无法读取其数值,报错信息为HPA cannot read metric value。

附上kubectl describe hpa -n aries的错误截图和Google Monitoring中的指标截图:
HPA错误描述
Cloud Monitoring中可见的指标

尝试通过GCP控制台配置HPA,仍出现相同错误。

补充信息

  • GKE版本:1.27.14-gke.1059002
  • 基于CPU资源的HPA可正常工作

HPA配置YAML文件

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: aries-celery-hpa
  namespace: aries
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: aries-celery
  minReplicas: {{ .Values.spec_celery.hpa.min_replicas }}
  maxReplicas: {{ .Values.spec_celery.hpa.max_replicas }}
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: {{ .Values.spec_celery.hpa.metrics.cpu.averageUtilization}}

  - type: External
    external:
      metric:
        name: prometheus.googleapis.com|aries_backlog_pressure|gauge
      target:
        type: AverageValue
        averageValue: 2

metrics.yaml文件内容

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: {{ .Values.app_name }}-metric-exporter
  name: {{ .Values.app_name }}-metric-exporter
  namespace: {{ .Values.namespace }}
spec:
  replicas: {{ .Values.spec.replicas }}
  selector:
    matchLabels:
      app: {{ .Values.app_name }}-metric-exporter
  template:
    metadata:
      labels:
        app: {{ .Values.app_name }}-metric-exporter
    spec:
      tolerations:
      - key: "low-cpu"
        operator: "Equal"
        effect: "NoSchedule"
        value: "true"

      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: "low-cpu"
                operator: "In"
                values:
                - "true"
      containers:
        - image: {{ .Values.image.name }}:{{ .Values.image.tag }}
          imagePullPolicy: IfNotPresent
          command: ["python3", "metrics.py"]
          name: {{ .Values.app_name }}-metric-exporter
          ports:
            - name: metrics
              containerPort: 8080
          volumeMounts:
            - name: aries-config
              readOnly: true
              mountPath: "/app/.env"
              subPath: .env
          resources:
            limits:
              cpu: {{ .Values.spec.resources.limits.cpu }}
              memory: {{ .Values.spec.resources.limits.memory }}

            requests:
              cpu: {{ .Values.spec.resources.requests.cpu }}
              memory: {{ .Values.spec.resources.requests.memory }}

      terminationGracePeriodSeconds: 10
      volumes:
        - name: aries-config
          configMap:
            name: aries-config
            items:
              - key: .env
                path: .env
            defaultMode: 420


---

apiVersion: v1
kind: Service
metadata:
  name: {{ .Values.app_name }}-metric-exporter
  namespace: aries
spec:
  selector:
    app: {{ .Values.app_name }}-metric-exporter
  ports:
  - protocol: TCP
    port: 80
    targetPort: metrics
  type: LoadBalancer

---

apiVersion: monitoring.googleapis.com/v1
kind: PodMonitoring
metadata:
  name: {{ .Values.app_name }}-metric-exporter
  namespace: {{ .Values.namespace }}
  labels:
    app.kubernetes.io/name: {{ .Values.app_name }}-metric-exporter
spec:
  selector:
    matchLabels:
      app: {{ .Values.app_name }}-metric-exporter
  endpoints:
  - port: metrics
    interval: 30s

内容的提问来源于stack exchange,提问作者radioactive11

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 16:33:11