<p>Is it possible to have the HPA scale based on the number of available running pods?</p>

<p>I have set up a readiness probe that cuts out a pod based it's internal state (idle, working, busy).  When a pod is 'busy', it no longer receives new requests.  But the cpu, and memory demands are low.</p>

<p>I don't want to scale based on cpu, mem, or other metrics.</p>

<p>Seeing as the readiness probe removes it from active service, can I scale based on the average number of active (not busy) pods?  When that number drops below a certain point more pods are scaled.</p>

<p>TIA for any suggestions.</p>

J.E.
<p>You can create <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-multiple-metrics-and-custom-metrics" rel="nofollow noreferrer">custom metrics</a>, a number of <code>busy-pods</code> for HPA.
That is, the application should emit a metric value when it is busy. And use that metric to create HorizontalPodAutoscaler.</p>

<p>Something like this:</p>

<pre><code>apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: custom-metric-sd
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1beta1
    kind: Deployment
    name: custom-metric-sd
  minReplicas: 1
  maxReplicas: 20
  metrics:
  - type: Pods
    pods:
      metricName: busy-pods
      targetAverageValue: 4
</code></pre>

<p><a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/custom-metrics-autoscaling" rel="nofollow noreferrer">Here</a> is another reference for HPA with custom metrics.</p>
