<p>I am trying to autoscale a deployment and a statefulset, by running respectivly these two commands:</p>
<pre><code>kubectl autoscale statefulset mysql --cpu-percent=50 --min=1 --max=10
kubectl expose deployment frontend --type=LoadBalancer --name=frontend
</code></pre>
<p>Sadly, on the minikube dashboard, this error appears under both services:</p>
<pre><code>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 (get pods.metrics.k8s.io)
</code></pre>
<p>Searching online I read that it might be a dns error, so I checked but CoreDNS seems to be running fine.
Both workloads are nothing special, this is the 'frontend' deployment:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
  labels:
    app: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: frontend
  template:
    metadata:
      labels:
        app: frontend
    spec:
      containers:
      - name: frontend
        image: hubuser/repo
        ports:
        - containerPort: 3000
</code></pre>
<p>Has anyone got any suggestions?</p>

<p>First of all, could you please verify if the API is working fine? To do so, please run <code>kubectl get --raw /apis/metrics.k8s.io/v1beta1</code>.</p>
<p>If you get an error similar to:</p>
<p>“<code>Error from server (NotFound)</code>:”</p>
<p>Please follow these steps:</p>
<p>1.- Remove all the proxy environment variables from the kube-apiserver manifest.</p>
<p>2.- In the kube-controller-manager-amd64, set <code>--horizontal-pod-autoscaler-use-rest-clients=false</code></p>
<p>3.- The last scenario is that your metric-server add-on is disabled by default. You can verify it by using:</p>
<p>$ minikube addons list</p>
<p>If it is disabled, you will see something like <code>metrics-server: disabled</code>.</p>
<p>You can enable it by using:</p>
<pre><code>$minikube addons enable metrics-server
</code></pre>
<p>When it is done, delete and recreate your HPA.</p>
<p>You can use the following <a href="https://github.com/kubernetes-sigs/metrics-server/issues/41" rel="nofollow noreferrer">thread</a> as a reference.</p>
