<p>Is there a way I can set up autoscaling with a complete customized algorithm?<br/>
1. I would like to autoscale my pods based on the ratio of (size of the azure storage queue) to (number of pods currently running) which means the average number of messages every pod needs to handle.<br/>
2. Can I create metrics and scale based on the metrics freely? Like<br/></p>

<pre><code>if 2 &gt; metrics &gt; 1:
     scale pods to 2
if 5 &gt; metrics &gt; 2:
     scale pods to 3
if 10 &gt; metrics &gt; 5:
     scale pods to 4
</code></pre>

<p>if so, where can I set up the autoscale algorithm?</p>

windgols
<p>You can use keda with the corresponding trigger for that: </p>

<p><a href="https://keda.sh/docs/1.4/scalers/azure-storage-queue/" rel="nofollow noreferrer">https://keda.sh/docs/1.4/scalers/azure-storage-queue/</a></p>

<p>Here is an example from the docs for azure storage queue.</p>

<pre><code> apiVersion: keda.k8s.io/v1alpha1
kind: TriggerAuthentication
metadata:
  name: azure-queue-auth
spec:
  podIdentity:
    provider: azure
---
apiVersion: keda.k8s.io/v1alpha1
kind: ScaledObject
metadata:
  name: azure-queue-scaledobject
  namespace: default
spec:
  scaleTargetRef:
    deploymentName: azurequeue-function
  triggers:
  - type: azure-queue
    metadata:
      # Required
      queueName: functionsqueue
      # Required: connection OR authenticationRef that defines connection
      connection: STORAGE_CONNECTIONSTRING_ENV_NAME # Default: AzureWebJobsStorage. Reference to a connection string in deployment
      # or authenticationRef as defined below
      #
      # Optional
      queueLength: "5" # default 5
    authenticationRef:
        name: azure-queue-auth # 
</code></pre>

<p>All kinds of other triggers are supported as well.</p>
