CodexBloom - Programming Q&A Platform

Kubernetes Horizontal Pod Autoscaler Ignoring CPU Request Limits in v1.22

πŸ‘€ Views: 351 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-16
kubernetes hpa autoscaling YAML

I'm converting an old project and I've been banging my head against this for hours. I'm sure I'm missing something obvious here, but I'm experiencing an issue with the Horizontal Pod Autoscaler (HPA) in my Kubernetes cluster running on v1.22... Despite having set resource requests and limits for CPU in my Deployment manifest, it seems that the HPA is not scaling the pods as expected. My deployment YAML looks like this: ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: my-app spec: replicas: 2 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: - name: my-container image: my-image:latest resources: requests: cpu: "500m" limits: cpu: "1000m" ``` I've also created the HPA using the following command: ```bash kubectl autoscale deployment my-app --cpu-percent=50 --min=1 --max=5 ``` However, after generating some load, I observed that the HPA is not scaling beyond the initial 2 replicas, even when the CPU utilization exceeds 50%. I've verified that the metrics server is deployed and functioning properly, as I can see CPU usage metrics when running: ```bash kubectl top pods ``` Additionally, I've checked the HPA status with: ```bash kubectl get hpa ``` It shows something like: ``` NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE my-app Deployment/my-app 30%/50% 1 5 2 10m ``` In this case, the TARGETS column shows that it’s not adjusting the replicas even though the metrics indicate that the CPU usage is high. I've also reviewed the HPA documentation and ensured that my metrics server is configured properly. Is there a specific limitation or configuration I'm overlooking that could be preventing the HPA from scaling based on the CPU requests and limits I’ve set? Any insights would be greatly appreciated! I'm working on a application that needs to handle this. Any help would be greatly appreciated! Am I missing something obvious? I appreciate any insights!