CodexBloom - Programming Q&A Platform

Kubernetes Horizontal Pod Autoscaler Not Scaling Pods Based on Custom Metrics in v1.30

👀 Views: 62 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-14
kubernetes hpa prometheus YAML

I'm integrating two systems and I'm currently working with a Kubernetes cluster version 1.30 and have set up a Horizontal Pod Autoscaler (HPA) to scale my deployments based on custom metrics fetched from Prometheus. However, I'm working with an scenario where the HPA doesn't seem to scale up the number of pods as expected when the custom metric thresholds are crossed. I have the following HPA configuration: ```yaml apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: my-app-hpa spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: my-app minReplicas: 2 maxReplicas: 10 metrics: - type: Pods pods: metric: name: request_count target: type: AverageValue averageValue: 100 ``` I've confirmed that my application is correctly emitting the `request_count` metric to Prometheus and that the metric is available through the Prometheus API. I can query the metric using: ```bash kubectl exec -it $(kubectl get pod -l app=my-app -o jsonpath='{.items[0].metadata.name}') -- curl -s http://localhost:9090/api/v1/query?query=request_count ``` This command returns the expected values, so the metric is being collected. Despite this, when I check the HPA status using: ```bash kubectl describe hpa my-app-hpa ``` I see that the current number of replicas remains constant at 2, and the metrics section shows `current: 80` and `desired: 2` despite the fact that the average request count is exceeding 100. I've also looked into the HPA logs but haven't found any errors that indicate a question. To troubleshoot this, I've checked the following: - Ensured that the `metrics-server` is properly deployed and running in the cluster. - Verified that I have the necessary RBAC permissions for the HPA to access the metrics. - Confirmed that the Prometheus adapter is correctly configured to expose the custom metrics. Is there something I'm missing here? Any insights on how to diagnose or resolve this scenario would be greatly appreciated! My development environment is Windows 11. Any feedback is welcome!