<p>I have GCP cluster which contains GKE application:
<a href="https://i.stack.imgur.com/LnEuR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LnEuR.jpg" alt="enter image description here"></a></p>

<p>I want to scale application using <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">HPA</a></p>

<p>Based on <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-metrics-apis" rel="nofollow noreferrer">supporting for metrics</a> </p>

<p><a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">HPA</a> able to read metrics from </p>

<ul>
<li><p>metrics.k8s.io (resource metrics)</p></li>
<li><p>custom.metrics.k8s.io(custom metrics)</p></li>
<li><p>external.metrics.k8s.io(external metrics)</p></li>
</ul>

<p>How could I check what metrics available? How could try this API  on my own ? Is it possible at all?</p>

<h2>P.S.</h2>

<p>Based on suggested answer I executed command:</p>

<pre><code> kubectl get --raw https://MY-KUBE-APISERVER-IP:6443/apis/metrics.k8s.io/v1beta1/namespaces/default/pods
</code></pre>

<p>Response is:</p>

<pre><code>{
  "items": [
    {
      "metadata": {
        "name": "prometheus-adapter-69fcdd56bc-2plh7",
        "namespace": "default",
        "selfLink": "/\r\napis/metrics.k8s.io/v1beta1/namespaces/default/pods/prometheus-adapter-69fcdd56bc-2plh7",
        "creationTimestamp": "2020-02-05T10:56:02Z"
      },
      "timestamp": "2020-02-05T10:55:22Z",
      "window": "30s",
      "containers": [
        {
          "name": "prometheus-adapter",
          "usage": {
            "cpu": "15\r\n31939n",
            "memory": "10408Ki"
          }
        }
      ]
    },
    {
      "metadata": {
        "name": "stackdriver-exporter-76fdbc9d8f-c285l",
        "namespace": "default",
        "selfLink": "/apis/metrics.k8s.io/v1beta1/namespaces/default/pods/stackdriver-exporter-76fdbc9d8f-c285l",
        "creationTimestamp": "2020-0\r\n2-05T10:56:02Z"
      },
      "timestamp": "2020-02-05T10:55:22Z",
      "window": "30s",
      "containers": [
        {
          "name": "stackdriver-exporter",
          "usage": {
            "cpu": "79340n",
            "memory": "2000Ki"
          }
        }
      ]
    }
  ],
  "kind": "PodMetricsList",
  "apiVersion": "metrics.k8s.io/v1beta1",
  "metadata": {
    "selfLink": "/apis/metrics.k8s.io/v1beta1/namespaces/default/pods"
  }
}


$ kubectl top pods
NAME                                    CPU(cores)   MEMORY(bytes)
prometheus-adapter-69fcdd56bc-2plh7     2m           10Mi
stackdriver-exporter-76fdbc9d8f-c285l   1m           1Mi
</code></pre>

<p>But I still don't see all metrics available for HPA</p>

gstackoverflow
<p>Metrics server exposes metrics via below APIs.</p>
<ol>
<li><code>/nodes</code> - all node metrics; <code>type []NodeMetrics</code></li>
<li><code>/nodes/{node}</code> - metrics for a specified node; <code>type NodeMetrics</code></li>
<li><code>/namespaces/{namespace}/pods</code> - all pod metrics within namespace with
support for all-namespaces; <code>type []PodMetrics</code></li>
<li><code>/namespaces/{namespace}/pods/{pod}</code> - metrics for a specified pod;
<code>type PodMetrics</code></li>
</ol>
<p>You can view available metrics as below for example</p>
<pre><code>$ kubectl get --raw https://KUBE-APISERVER-IP:6443/apis/metrics.k8s.io/v1beta1
{
  &quot;kind&quot;: &quot;APIResourceList&quot;,
  &quot;apiVersion&quot;: &quot;v1&quot;,
  &quot;groupVersion&quot;: &quot;metrics.k8s.io/v1beta1&quot;,
  &quot;resources&quot;: [
    {
      &quot;name&quot;: &quot;nodes&quot;,
      &quot;singularName&quot;: &quot;&quot;,
      &quot;namespaced&quot;: false,
      &quot;kind&quot;: &quot;NodeMetrics&quot;,
      &quot;verbs&quot;: [
        &quot;get&quot;,
        &quot;list&quot;
      ]
    },
    {
      &quot;name&quot;: &quot;pods&quot;,
      &quot;singularName&quot;: &quot;&quot;,
      &quot;namespaced&quot;: true,
      &quot;kind&quot;: &quot;PodMetrics&quot;,
      &quot;verbs&quot;: [
        &quot;get&quot;,
        &quot;list&quot;
      ]
    }
  ]
}

$ kubectl get --raw https://KUBE-APISERVER-IP:6443/apis/metrics.k8s.io/v1beta1/namespaces/default/pods
{
  &quot;kind&quot;: &quot;PodMetricsList&quot;,
  &quot;apiVersion&quot;: &quot;metrics.k8s.io/v1beta1&quot;,
  &quot;metadata&quot;: {
    &quot;selfLink&quot;: &quot;/apis/metrics.k8s.io/v1beta1/namespaces/default/pods&quot;
  },
  &quot;items&quot;: []
}

$ kubectl get --raw https://KUBE-APISERVER-IP:6443/apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods
{
  &quot;kind&quot;: &quot;PodMetricsList&quot;,
  &quot;apiVersion&quot;: &quot;metrics.k8s.io/v1beta1&quot;,
  &quot;metadata&quot;: {
    &quot;selfLink&quot;: &quot;/apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods&quot;
  },
  &quot;items&quot;: [
    {
      &quot;metadata&quot;: {
        &quot;name&quot;: &quot;coredns-bcccf59f-jfl6x&quot;,
        &quot;namespace&quot;: &quot;kube-system&quot;,
        &quot;selfLink&quot;: &quot;/apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods/coredns-bcccf59f-jfl6x&quot;,
        &quot;creationTimestamp&quot;: &quot;2021-02-17T20:31:29Z&quot;
      },
      &quot;timestamp&quot;: &quot;2021-02-17T20:30:27Z&quot;,
      &quot;window&quot;: &quot;30s&quot;,
      &quot;containers&quot;: [
        {
          &quot;name&quot;: &quot;coredns&quot;,
          &quot;usage&quot;: {
            &quot;cpu&quot;: &quot;1891053n&quot;,
            &quot;memory&quot;: &quot;8036Ki&quot;
          }
        }
      ]
    },
    {
      &quot;metadata&quot;: {
        &quot;name&quot;: &quot;coredns-bcccf59f-vmfvv&quot;,
        &quot;namespace&quot;: &quot;kube-system&quot;,
        &quot;selfLink&quot;: &quot;/apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods/coredns-bcccf59f-vmfvv&quot;,
        &quot;creationTimestamp&quot;: &quot;2021-02-17T20:31:29Z&quot;
      },
      &quot;timestamp&quot;: &quot;2021-02-17T20:30:25Z&quot;,
      &quot;window&quot;: &quot;30s&quot;,
      &quot;containers&quot;: [
        {
          &quot;name&quot;: &quot;coredns&quot;,
          &quot;usage&quot;: {
            &quot;cpu&quot;: &quot;1869226n&quot;,
            &quot;memory&quot;: &quot;8096Ki&quot;
          }
        }
      ]
    }
  ]
}
</code></pre>
<p>You can also use command <code>kubectl top pods</code> which internally calls the above API.</p>
<p><strong>Custom Metrics</strong></p>
<p>These are provided by adapters developed by vendors and what metrics are available will depend on the adapter. Once you know the metrics name You can use <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/custom-metrics-api.md" rel="noreferrer">API</a> to access it.</p>
<p>You can view available metrics as below and get the metrics name.</p>
<pre><code>kubectl get --raw https://KUBE-APISERVER-IP:6443/apis/custom.metrics.k8s.io/v1beta1
</code></pre>
<p><strong>External Metrics</strong></p>
<p>These are provided by adapters developed by vendors and what metrics are available will depend on the adapter. Once you know the metrics name You can use <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/external-metrics-api.md" rel="noreferrer">API</a> to access it.</p>
<p>You can view available metrics as below and get the metrics name.</p>
<pre><code>kubectl get --raw https://KUBE-APISERVER-IP:6443/apis/external.metrics.k8s.io/v1beta1
</code></pre>
<p><strong>Edit:</strong></p>
<p>You already have Prometheus adapter but if the metric is not exposed as custom metrics to be consumable by HPA then you need to expose the required metrics. Refer to this <a href="https://itnext.io/horizontal-pod-autoscale-with-custom-metrics-8cb13e9d475" rel="noreferrer">guide</a> for this.</p>
