I try to use Horizontal Pod Autosclaer
for nginx
pod.
When I describe my hpa I have this message horizontal-pod-autoscaler failed to get cpu utilization: unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API: the server could not find the requested resource
I use docker for mac. I don't know if it can have an impact
My deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-app
spec:
selector:
matchLabels:
run: demo-app
replicas: 1
template:
metadata:
labels:
run: demo-app
spec:
containers:
- name: demo-app
image: my-demo-app:v3
imagePullPolicy: Never
resources:
requests:
cpu: 250m
limits:
cpu: 300m
ports:
- containerPort: 80
My HPA
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: demo-app-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: demo-app
minReplicas: 1
maxReplicas: 3
targetCPUUtilizationPercentage: 3
Output of kubectl get hpa command :
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
demo-app-hpa Deployment/demo-app <unknown>/3% 1 3 1 20m
Output of kubectl get --raw /apis/metrics.k8s.io/v1beta1
command
{"kind":"APIResourceList","apiVersion":"v1","groupVersion":"metrics.k8s.io/v1beta1","resources":[{"name":"nodes","singularName":"","namespaced":false,"kind":"NodeMetrics","verbs":["get","list"]},{"name":"pods","singularName":"","namespaced":true,"kind":"PodMetrics","verbs":["get","list"]}]}
I configure metric-server with this but not work
Scaling active
is set to False. I think it's the problem but I don't know how change value
Looks like you are missing metrics server.
The HorizontalPodAutoscaler normally fetches metrics from a series of aggregated APIs (
metrics.k8s.io
,custom.metrics.k8s.io
, andexternal.metrics.k8s.io
). Themetrics.k8s.io
API is usually provided by metrics-server, which needs to be launched separately. See metrics-server for instructions. The HorizontalPodAutoscaler can also fetch metrics directly from Heapster.
You can check if there are metrics deployed by kubectl get --raw /apis/metrics.k8s.io/v1beta1
.
To install metrics-server just clone the repo and run kubectl create -f deploy/1.8+/
If you still have the issue I recommend checking Docker Kubernetes (Mac) - Autoscaler unable to find metrics.