<p>I want to add custom metrics to my existing cpu metric, so I want two metrics.
My second metrics has to be a custom metric/external metrics which makes a request to a webserver and gets there a value, is this possible?</p>

<p>At the moment it looks like this but I want to add a second metric but how?</p>

<pre><code>  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 80
</code></pre>

<p>As I read in the docs kubernetes would use the higher metric to scale thats ok.
Does someone have an example for me how to apply this custom metric in my case?</p>

<p>If it's an external metric (i.e. a custom metric that is <em>not</em> associated with a Kubernetes object):</p>

<pre><code> metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 80
  - type: External
    external:
      metric:
        name: your_metric
      target:
        type: Value
        value: "100"
</code></pre>

<p>Note that in this case, the HPA will try to query the <code>your_metric</code> metric from the <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/external-metrics-api.md" rel="nofollow noreferrer">External Metrics API</a>. That means, this API must exist in your cluster for this configuration to work.</p>

<p>If the metric is associated with a Kubernetes object, you would use a <code>type: Object</code> and if the metric is from the pods of the pod controller (e.g. Deployment) that you are trying to autoscale, you would use a <code>type: Pods</code>. In both cases, the HPA would try to fetch the metric from the <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/custom-metrics-api.md" rel="nofollow noreferrer">Custom Metrics API</a>.</p>

<hr>

<p>Note (because it seems that you are trying to use a metric that is not yet in Kubernetes):</p>

<p>The HPA can only talk to the metric APIs: <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/resource-metrics-api.md" rel="nofollow noreferrer">Resource Metrics API</a>, <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/custom-metrics-api.md" rel="nofollow noreferrer">Custom Metrics API</a>, <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/external-metrics-api.md" rel="nofollow noreferrer">External Metrics API</a>.</p>

<p>If your metric is not served by one of these APIs, then you have to create a metrics pipeline that brings the metric to one of these APIs.</p>

<p>For example, using <a href="https://prometheus.io/" rel="nofollow noreferrer">Prometheus</a> and the <a href="https://github.com/DirectXMan12/k8s-prometheus-adapter" rel="nofollow noreferrer">Prometheus Adapter</a>:</p>

<ul>
<li>Prometheus periodically scrapes the metric from your external web server</li>
<li>Prometheus Adapter exposes the metric through the External Metrics API</li>
</ul>

<hr>

<p><em><strong>EDIT:</strong> explain metric APIs.</em></p>

<p><em>In the diagrams below, the green components are those that you need to install to provide the corresponding metric API.</em></p>

<h3><a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/resource-metrics-api.md" rel="nofollow noreferrer">Resource Metrics API</a></h3>

<p>Serves CPU and memory usage metrics of all Pods and Nodes in the cluster. These are predefined metric (in contrast to the custom metrics of the other two APIs).</p>

<p>The raw data for the metrics is collected by <a href="https://github.com/google/cadvisor" rel="nofollow noreferrer">cAdvisor</a> which runs as part of the kubelet on each node. The metrics are exposed by the <a href="https://github.com/kubernetes-incubator/metrics-server" rel="nofollow noreferrer">Metrics Server</a>.</p>

<p>The Metrics Server implements the Resource Metrics API. It is not installed by default in Kubernetes. That means, to enable the Resource Metrics API in your cluster, you have to install the Metrics Server.</p>

<p><a href="https://i.stack.imgur.com/ChTdi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ChTdi.png" alt="enter image description here"></a></p>

<h3><a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/custom-metrics-api.md" rel="nofollow noreferrer">Custom Metrics API</a></h3>

<p>Serves custom metrics that are associated with Kubernetes objects. The metrics can be anything you want.</p>

<p>You are responsible yourself for collecting the metrics that you want to expose through the Custom Metrics API. You do this by installing a "metrics pipeline" in the cluster.</p>

<p>You can choose the components for your metrics pipeline yourself. The only requirement is that the metrics pipeline is able to:</p>

<ol>
<li>Collect metrics</li>
<li>Implement the Custom Metrics API</li>
</ol>

<p>A popular choice for a metrics pipeline is to use <a href="https://prometheus.io/" rel="nofollow noreferrer">Prometheus</a> and the <a href="https://github.com/DirectXMan12/k8s-prometheus-adapter" rel="nofollow noreferrer">Prometheus Adapter</a>:</p>

<ul>
<li>Prometheus collects metrics (any metrics you want)</li>
<li>Prometheus Adapter implements the Custom Metrics API and exposes the metrics collected by Prometheus through the Custom Metrics API</li>
</ul>

<p><a href="https://i.stack.imgur.com/JZZ9o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JZZ9o.png" alt="enter image description here"></a></p>

<h3><a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/external-metrics-api.md" rel="nofollow noreferrer">External Metrics API</a></h3>

<p>Serves custom metrics that are not associated with Kubernetes objects.</p>

<p>The External Metrics API works identical to the Custom Metrics API. The only difference is that it has different API paths (that don't include objects, but only metric names).</p>

<p>To provide the External Metrics API you can, in most cases, use the same metrics pipeline as for the Custom Metrics API (e.g. Prometheus and the Prometheus Adapter).</p>

<p><a href="https://i.stack.imgur.com/uti6t.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uti6t.png" alt="enter image description here"></a></p>
