<p>I am using <strong>minikube on Windows</strong>, there is only one node "master".</p>

<p>The spring boot application deployed <strong><em>has REST endpoint which gives the number of client its currently serving</em></strong>. I would like to scale out horizontally or auto spin a pod when the requests reaches some limit.</p>

<pre><code>Lets say:
There is 1 pod in the cluster.
If the request limit reached 50 (for Pod 1), spin up a new pod.
If the request limit reached 50 for Pod 1 and Pod 2, spin up a new Pod (Pod 3).
</code></pre>

<p>I tried researching on how to achieve this, I was not able to figure out any.
All I could find was scaling out using CPU usage with HorizontalPodAutoscaler(HPA).
Would be helpful to receive a guidance on how to achieve this using <strong>Kubernetes HPA</strong>.</p>

<p>I believe you can start from the <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-multiple-metrics-and-custom-metrics" rel="nofollow noreferrer">autoscaling on custom metrics article</a>. As per I see - this is achievable using the custom metrics in conjunction with <a href="https://github.com/DirectXMan12/k8s-prometheus-adapter" rel="nofollow noreferrer">Prometheus Adapter for Kubernetes Metrics APIs</a> (An implementation of the custom.metrics.k8s.io API using Prometheus).</p>

<p><a href="https://github.com/DirectXMan12/k8s-prometheus-adapter" rel="nofollow noreferrer">Prometheus Adapter for Kubernetes Metrics APIs repo</a> contains an implementation of the Kubernetes <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/resource-metrics-api.md" rel="nofollow noreferrer">resource metrics</a> API and <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/custom-metrics-api.md" rel="nofollow noreferrer">custom metrics</a> API. </p>

<p>This adapter is therefore suitable for use with the autoscaling/v2 Horizontal Pod Autoscaler in Kubernetes 1.6+.</p>

<p>Info from <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-multiple-metrics-and-custom-metrics" rel="nofollow noreferrer">autoscaling on custom metrics</a>: </p>

<blockquote>
  <p>Notice that you can specify other resource metrics besides CPU. By
  default, the only other supported resource metric is memory. These
  resources do not change names from cluster to cluster, and should
  always be available, as long as the metrics.k8s.io API is available.</p>
</blockquote>

<p>The first of these alternative metric types is pod metrics. These metrics describe pods, and are averaged together across pods and compared with a target value to determine the replica count. They work much like resource metrics, except that they only support a target type of AverageValue.</p>

<p>Pod metrics are specified using a metric block like this:</p>

<pre><code>type: Pods
pods:
  metric:
    name: packets-per-second
  target:
    type: AverageValue
    averageValue: 1k
</code></pre>

<p>The second alternative metric type is object metrics. These metrics describe a different object in the same namespace, instead of describing pods. The metrics are not necessarily fetched from the object; they only describe it. Object metrics support target types of both Value and AverageValue. With Value, the target is compared directly to the returned metric from the API. With AverageValue, the value returned from the custom metrics API is divided by the number of pods before being compared to the target. The following example is the YAML representation of the requests-per-second metric.</p>

<pre><code>type: Object
object:
  metric:
    name: requests-per-second
  describedObject:
    apiVersion: networking.k8s.io/v1beta1
    kind: Ingress
    name: main-route
  target:
    type: Value
    value: 2k
</code></pre>

<p>Also maybe below will be helpful for your future investigations:</p>

<p><a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-more-specific-metrics" rel="nofollow noreferrer">Autoscaling on more specific metrics</a></p>

<p><a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-metrics-not-related-to-kubernetes-objects" rel="nofollow noreferrer">Autoscaling on metrics not related to Kubernetes objects</a></p>

<p>Hope it helps</p>
