Kubernetes HPA -- Unable to get metrics for resource memory: no metrics returned from resource metrics API
The error unable to get metrics for resource memory: no metrics returned from resource metrics API
is not caused by faulty HPA but by metrics-server that is not able to scrape any metrics.
Most of the time this error is caused by missing commands in metrics-server deployment. It can be done by adding following arguments in the deployment.
--kubelet-insecure-tls --kubelet-preferred-address-types=InternalIP,ExternalIP
Since you are using apiVersion: autoscaling/v2beta2 , the correct way to specify scaling policy based on resources would be,
type: Resourceresource: name: cpu target: type: Utilization averageUtilization: 60
You can also specify resource metrics in terms of direct values, instead of as percentages of the requested value, by using a target.type of AverageValue instead of Utilization, and setting the corresponding target.averageValue
field instead of the target.averageUtilization
And if you want to try out with v2beta1, you can try the below piece of yml in metrics,
type: Resource resource: name: memory targetAverageUtilization: 60
The problem is at:
target:type: AverageValueaverageUtilization: 50
You specified the type "AverageValue" but with "averageUtilization". You should either change type: to "Utilization" or value field with "averageValue".