Azure AKS HPA failed to get cpu utilization

10/22/2018

I have a single node K8s cluster in Azure using AKS. I created a deployment and a service using a simple command:

kubectl run php-apache --image=pilchard/hpa-example:latest --requests=cpu=200m,memory=300M --expose --port=80

And enabled HPA via command: kubectl autoscale deployment php-apache --cpu-percent=10 --min=1 --max=15

Upon running kubectl describe hpa php-apache, I see an error saying:

horizontal-pod-autoscaler  unable to get metrics for resource cpu: unable to fetch metrics from API: the server could not find the requested resource (get pods.metrics.k8s.io)
horizontal-pod-autoscaler  failed to get cpu utilization: unable to get metrics for resource cpu: unable to fetch metrics from API: the server could not find the requested resource (get pods.metrics.k8s.io)

And CPU metric is unknown upon running kubectl get hpa. Any help would be really appreciated.

My AKS kube version is v1.9.11.

-- Janshair Khan
autoscaling
azure
azure-aks
kubernetes

1 Answer

10/22/2018

You either need to install the heapster(Deprecated) or the metrics-server minimally to be able to use an HPA.

This provides the minimum set of CPU and Memory metrics to be able to autoscale. A good way to see if you have either installed is that if you get this kind output from kubectl top pod:

$ kubectl top pod
NAME                        CPU(cores)   MEMORY(bytes)
http-svc-xxxxxxxxxx-xxxxx   1m           7Mi
myapp-pod                   0m           53Mi
sleep-xxxxxxxxxx-xxxxx      4m           27Mi
-- Rico
Source: StackOverflow