<p>I have installed a local instance of Kubernetes via Docker on my Mac. </p>

<p>Following the <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/" rel="noreferrer">walkthrough</a> on how to activate autoscaling on a deployment I have experienced an issue. The autoscaler can't read the metrics.</p>

<p>When I am running <code>kubectl describe hpa</code> the current cpu usage comes back as <strong>unknown / 50%</strong> with the warnings:</p>

<blockquote>
  <p>Warning  FailedGetResourceMetric:
  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)   </p>
  
  <p>Warning FailedComputeMetricsReplicas 
  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)</p>
</blockquote>

<p>I have installed the metrics-server via <code>git clone https://github.com/kubernetes-incubator/metrics-server.git</code>and installed it with <code>kubectl create -f deploy/1.8+</code></p>

<p>I finally got it working..
Here are the full steps I took to get things working:</p>
<ol>
<li><p>Have Kubernetes running within Docker</p>
</li>
<li><p>Delete any previous instance of metrics-server from your Kubernetes instance with <code>kubectl delete -n kube-system deployments.apps metrics-server</code></p>
</li>
<li><p>Clone metrics-server with <code>git clone https://github.com/kubernetes-incubator/metrics-server.git</code></p>
</li>
<li><p>Edit the file <strong>deploy/1.8+/metrics-server-deployment.yaml</strong> to override the default command by adding a <strong>command</strong> section that didn't exist before. The new section will instruct metrics-server to allow for an insecure communications session (don't verify the certs involved). Do this only for Docker, and not for production deployments of metrics-server:</p>
<pre><code>containers:
- name: metrics-server
    image: k8s.gcr.io/metrics-server-amd64:v0.3.1
    command:
      - /metrics-server
      - --kubelet-insecure-tls
</code></pre>
</li>
<li><p>Add metrics-server to your Kubernetes instance with <code>kubectl create -f deploy/1.8+</code> (if errors with the .yaml, write this instead: <code>kubectl apply -f deploy/1.8+</code>)</p>
</li>
<li><p>Remove and add the autoscaler to your deployment again. It should now show the current cpu usage.</p>
</li>
</ol>
<p><strong>EDIT July 2020:</strong></p>
<p>Most of the above steps hold true except the <a href="https://github.com/kubernetes-sigs/metrics-server" rel="noreferrer">metrics-server</a> has changed and that file does not exist anymore.</p>
<p>The repo now recommends installing it like this:</p>
<pre><code>apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml
</code></pre>
<p>So we can now download this file,</p>
<pre><code>curl -L https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml --output components.yaml
</code></pre>
<p>add <code>--kubelet-insecure-tls</code> under <code>args</code> (L88) to the <code>metrics-server</code> deployment and run</p>
<pre><code>kubectl apply -f components.yaml
</code></pre>
