Kubernetes HPA unable to fetch custom metrics from Prometheus Adapter

I am facing an issue with Kubernetes Horizontal Pod Autoscaler (HPA) which is unable to fetch custom metrics from the Prometheus Adapter. Despite following the configuration steps and verifying that metrics are available, the HPA reports no metrics.

Environment Details:

Kubernetes version: v1.28.2

Prometheus Adapter version: v0.11.2

Custom Metrics API is configured and available

Prometheus Adapter Configuration:

My values.yaml configuration for the Prometheus Adapter is as follows:

rules:
  default: false
  custom:
    - seriesQuery: 'app_horizon_current_workload{queue!=""}'
      resources:
        overrides:
          namespace:
            resource: "namespace"
          pod:
            resource: "pod"
      name:
        matches: "app_horizon_current_workload"
        as: "app_horizon_max_workload"
      metricsQuery: 'max(<<.Series>>{<<.LabelMatchers>>,queue!=""}) by (<<.GroupBy>>)'

Horizontal Pod Autoscaler (HPA) Configuration:

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: hpa-queue-worker
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: queue-worker
  minReplicas: 4
  maxReplicas: 16
  metrics:
    - type: Pods
      pods:
        metric:
          name: app_horizon_max_workload
        target:
          type: AverageValue
          averageValue: "10"

RBAC Configuration:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: custom-metrics-reader
rules:
- apiGroups: ["custom.metrics.k8s.io"]
  resources: ["*"]
  verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: custom-metrics-reader-binding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: custom-metrics-reader
subjects:
- kind: ServiceAccount
  name: hpa-controller
  namespace: kube-system

Logs and Metrics Verification:

1. Prometheus Adapter Logs:

I0724 07:33:07.448719       1 httplog.go:132] "HTTP" verb="GET" URI="/apis/custom.metrics.k8s.io/v1beta1/namespaces/default/pods/%2A/app_horizon_max_workload" latency="36.854307ms" userAgent="kubectl/v1.30.2 (linux/amd64) kubernetes/3968350" audit-ID="9dbd3da1-3262-47f4-900e-37057a6545a6" srcIP="10.244.3.42:51390" resp=200

2. Prometheus Query:

Executing the Prometheus query max(app_horizon_current_workload{queue!=””}) by (namespace, pod) returns the expected results:

{
  "namespace": "default",
  "pod": "pod-1"
}
22
{
  "namespace": "default",
  "pod": "pod-2"
}
24

3. kubectl Custom Metrics API:

Running kubectl get --raw '/apis/custom.metrics.k8s.io/v1beta1/namespaces/default/pods/*/app_horizon_max_workload' | jq . I get:

{
  "kind": "MetricValueList",
  "apiVersion": "custom.metrics.k8s.io/v1beta1",
  "metadata": {},
  "items": [
    {
      "describedObject": {
        "kind": "Pod",
        "namespace": "default",
        "name": "pod-1",
        "apiVersion": "/v1"
      },
      "metricName": "app_horizon_max_workload",
      "timestamp": "2024-07-24T07:33:07Z",
      "value": "22",
      "selector": null
    },
    {
      "describedObject": {
        "kind": "Pod",
        "namespace": "default",
        "name": "pod-2",
        "apiVersion": "/v1"
      },
      "metricName": "app_horizon_max_workload",
      "timestamp": "2024-07-24T07:33:07Z",
      "value": "24",
      "selector": null
    }
  ]
}

Issue:

Despite the custom metrics being available, the HPA reports <unknown> for the metrics and fails to scale:

Running kubectl describe hpa hpa-queue-worker -n default I get:

Name:                                  hpa-queue-worker
Namespace:                             default
Metrics:                               ( current / target )
  "app_horizon_max_workload" on pods:  <unknown> / 10
Conditions:
  Type           Status  Reason               Message
  ----           ------  ------               -------
  AbleToScale    True    SucceededGetScale    the HPA controller was able to get the target's current scale
  ScalingActive  False   FailedGetPodsMetric  the HPA was unable to compute the replica count: unable to get metric app_horizon_max_workload: no metrics returned from custom metrics API
Events:
  Warning  FailedGetPodsMetric           0s (x2 over 15s)  horizontal-pod-autoscaler  unable to get metric app_horizon_max_workload: no metrics returned from custom metrics API
  Warning  FailedComputeMetricsReplicas  0s (x2 over 15s)  horizontal-pod-autoscaler  invalid metrics (1 invalid out of 1), first error is: failed to get pods metric value: unable to get metric app_horizon_max_workload: no metrics returned from custom metrics API

Question:
What might be causing the HPA to fail to fetch custom metrics from the Prometheus Adapter? How can I resolve this issue to enable the HPA to scale based on custom metrics?

Any help or suggestions would be greatly appreciated. Thank you!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật