Fix GCP GKE Hpa Metric Errors
When working with GCP GKE, you may encounter a configuration error that prevents your deployment from working. This guide explains the most common mistake with hpa metric and shows the exact fix.
A Common Mistake
Creating a HorizontalPodAutoscaler (HPA) using an incorrect metric name or format, causing the HPA to be unable to read metrics and never scale.
The incorrect command:
kubectl autoscale deployment my-app --cpu-percent=80 --min=3 --max=10
Error output:
horizontalpodautoscaler.autoscaling/my-app autoscaled
But no metrics are available:
kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
my-app Deployment/my-app <unknown>/80% 3 10 3 5m
The HPA shows <unknown> targets because metrics-server is not installed or the metric name is incorrect.
The Correct Approach
The right way to configure hpa metric in GCP GKE:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml && kubectl autoscale deployment my-app --cpu-percent=80 --min=3 --max=10
Successful result:
Metrics server installed.
kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
my-app Deployment/my-app 45%/80% 3 10 3 5m
The HPA reads CPU metrics and scales the deployment as needed.
How to Prevent This
Install metrics-server before using HPA. Verify with kubectl top pods. Use custom metrics for application-specific scaling. Set min and max pods to bound costs. HPA works on CPU, memory, and custom metrics. Test HPA with load testing tools. Monitor HPA decisions with kubectl describe hpa.
FAQ
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Secure your cloud with DodaTech.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro