<p>I have a two node Kubernetes cluster i.e one master node and two worker nodes. For monitoring purpose, I have deployed Prometheus and Grafana. Now, I want to autoscale pods based on CPU usage. But even after configuring Grafana and Prometheus, I am getting the following error ---</p>

<pre><code>Name:                                                  php-apache
Namespace:                                             default
Labels:                                                &lt;none&gt;
Annotations:                                           &lt;none&gt;
CreationTimestamp:                                     Mon, 17 Jun 2019 12:33:01 +0530
Reference:                                             Deployment/php-apache
Metrics:                                               ( current / target )
  resource cpu on pods  (as a percentage of request):  &lt;unknown&gt; / 50%
Min replicas:                                          1
Max replicas:                                          10
Deployment pods:                                       1 current / 0 desired
Conditions:
  Type           Status  Reason                   Message
  ----           ------  ------                   -------
  AbleToScale    True    SucceededGetScale        the HPA controller was able to get the target's current scale
  ScalingActive  False   FailedGetResourceMetric  the HPA was unable to compute the replica count: 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)
Events:
  Type     Reason                   Age                      From                       Message
  ----     ------                   ----                     ----                       -------
  Warning  FailedGetResourceMetric  112s (x12408 over 2d4h)  horizontal-pod-autoscaler  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>Can anybody let me know why Kubernetes is not fetching metrics from Prometheus ?</p>

<p>Kubernetes retrieves metrics from either the <code>metrics.k8s.io</code> API (normally implemented by the <code>metrics-server</code> which can be seperatly installed) or the <code>custom.metrics.k8s.io</code> API (which can be any type of metric and is normally provided by third parties). To use prometheus in HPA for kubernetes the <a href="https://github.com/directxman12/k8s-prometheus-adapter" rel="nofollow noreferrer">Prometheus Adapter</a> for the custom metrics API needs to be installed.</p>

<p>A walkthrough for the setup can be found <a href="https://github.com/DirectXMan12/k8s-prometheus-adapter/blob/master/docs/walkthrough.md" rel="nofollow noreferrer">here</a>.</p>
