<p>Pods come down to 0 but it doesnt spin up more than 1 pod. Even if more than 5mgs are there in the subscription
Updated code as per suggestions.</p>
<p>Added TriggerAuthentication and used connectionString as authentication. Tried to send around 25messages, but still pod is not scaling up.</p>
<p>Only one pod is handling all the messages. Do I need to update anything</p>
<pre><code>apiVersion: keda.k8s.io/v1alpha1
kind: TriggerAuthentication
metadata:
  name: azure-servicebus-auth
spec:
  secretTargetRef:
    - parameter: connection
      name: mdsp-secret-infra
      key: service_bus_conn_str
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: xyz-test
  labels:
    app: xyz-test
spec:
  selector:
    matchLabels:
      app: xyz-test
  template:
    metadata:
      labels:
        app: xyz-test
    spec:
      initContainers:
        - name: mdsp-java-init
          image: aksacrname.azurecr.io/ops/mdsp-init-java:1.0
          imagePullPolicy: Always
          resources: {}
          volumeMounts:
            - name: azure
              mountPath: /mnt/azure
            - name: cert-storage
              mountPath: /certs
      volumes:
        - name: azure
          azureFile:
            shareName: certs
            secretName: mdsp-secret-iots-sa
            readOnly: true
        - name: cert-storage
          emptyDir: {}
        - name: &quot;logging-volume-azure-file&quot;
          persistentVolumeClaim:
            claimName: &quot;pvc-azure-file-logging&quot;
      containers:
        - name: xyz-test
          image: mdspaksdevacr.azurecr.io/iots/xyz-test:aksacrversion
          resources:
            limits:
              cpu: 3
              memory: 2Gi
            requests:
              cpu: 1
              memory: 1Gi
          imagePullPolicy: Always
          env:
            - name: mdsp_product_line
              value: &quot;iiotservices&quot;
            - name: mdsp_application_name
              value: &quot;xyz-test&quot;
            - name: eh_connection_string
              valueFrom:
                secretKeyRef:
                  name: mdsp-secret-iots-kv
                  key: LOGGING_EH_CON_STRING
            - name: log_base_path
              value: &quot;/mnt/logging&quot;
            - name: app.logging.console.enabled
              value: &quot;true&quot;
            - name: ai_instrumentation_key
              valueFrom:
                secretKeyRef:
                  name: mdsp-secret-iots-kv
                  key: APPINSIGHT_KEY
            - name: MDSP_HOST_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: MDSP_HOST_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: APPLICATION_NAME
              value: &quot;xyz-test&quot;
            - name: logging.level.com.siemens.mindsphere
              value: &quot;INFO&quot;
            - name: PRODUCTLINE_NAME
              value: &quot;iiotServices&quot;
            - name: environment
              value: &quot;azEnvironment&quot;
            - name: CONNECTION_TIMEOUT_MS
              value: &quot;10000&quot;
            - name: GATEWAY_URI
              value: &quot;https://gateway.core.mindsphere.local&quot;
            - name: UPDATES_SERVICE_BUS_TOPIC_NAME
              value: &quot;internal-iiot-meta-data-updates-topic&quot;
            - name: ASSET_CLIENTID
              value: asset
            - name: AM_BASE_URL
              value: &quot;https://gateway.core.mindsphere.local/api/assetmanagement/v3&quot;
            - name: CORE_AUTH_TOKEN_URL
              valueFrom:
                configMapKeyRef:
                  name: mdsp-iots-configmap
                  key: OAUTH_TOKEN_URI
            - name: amServiceBusConnectionString
              valueFrom:
                secretKeyRef:
                  name: mdsp-iots-secret-infra
                  key: advs_servicebus_conn_str
            - name: feedbackServiceBusConnectionString
              value: &quot;Endpoint=sb://iot-test-rc.servicebus.windows.net/;SharedAccessKeyName=Testkey;SharedAccessKey=test&quot;
            - name: UPDATES_SERVICE_BUS_CONN_STR
              valueFrom:
                secretKeyRef:
                  name: mdsp-iots-secret-infra
                  key: iots_service_bus_conn_str
            - name: AZURE_CLIENT_ID
              valueFrom:
                secretKeyRef:
                  name: mdsp-secret-iots-kv
                  key: KEYVAULT_CLIENT_ID
            - name: AZURE_CLIENT_SECRET
              valueFrom:
                secretKeyRef:
                  name: mdsp-secret-iots-kv
                  key: KEYVAULT_CLIENT_KEY
            - name: AZURE_SUBSCRIPTION_ID
              valueFrom:
                secretKeyRef:
                  name: mdsp-secret-iots-kv
                  key: SUBSCRIPTION_ID
            - name: AZURE_TENANT_ID
              valueFrom:
                secretKeyRef:
                  name: mdsp-secret-iots-kv
                  key: TENANT_ID
            - name: KV_CLIENT_ID
              valueFrom:
                secretKeyRef:
                  name: mdsp-secret-iots-kv
                  key: KEYVAULT_CLIENT_ID
            - name: KV_CLIENT_SECRET
              valueFrom:
                secretKeyRef:
                  name: mdsp-secret-iots-kv
                  key: KEYVAULT_CLIENT_KEY
            - name: JAVA_OPTS
              value: &gt;-
                -Djavax.net.ssl.trustStore=/certs/cacerts
                -Xmx2500m
            - name: KEYVAULT_URI
              valueFrom:
                configMapKeyRef:
                  name: mdsp-iots-configmap
                  key: IOTS_KEYVAULT_URI
            - name: COSMOS_URL
              valueFrom:
                configMapKeyRef:
                  name: mdsp-iots-configmap
                  key: IOT_COSMOS_URI
            - name: default_key
              valueFrom:
                secretKeyRef:
                  name: mdsp-iots-secret-infra
                  key: iots_cosmos_db_conn_key
            - name: COSMOS_DB_NAME
              valueFrom:
                configMapKeyRef:
                  name: mdsp-iots-configmap
                  key: IOT_COSMOS_DB_AM
            - name: COSMOS_CONTAINER_NAME
              valueFrom:
                configMapKeyRef:
                  name: mdsp-iots-configmap
                  key: IOT_COSMOS_CON_AM
            - name: default_secret_name
              valueFrom:
                secretKeyRef:
                  name: mdsp-secret-iots-tu
                  key: iots_bulk_data_stream
            - name: MINDSPHERE_SECURITY_OAUTH2_CLIENT_ASSET_ACCESSTOKENURI
              valueFrom:
                configMapKeyRef:
                  name: mdsp-iots-configmap
                  key: OAUTH_TOKEN_URI
            - name: MINDSPHERE_SECURITY_OAUTH2_CLIENT_ASSET_ID
              value: &quot;iottest&quot;


          volumeMounts:
            - name: cert-storage
              mountPath: /certs
            - name: &quot;logging-volume-azure-file&quot;
              mountPath: &quot;/mnt/logging&quot;
      imagePullSecrets:
        - name: mdsp-secret-iots
      dnsPolicy: ClusterFirst
      terminationGracePeriodSeconds: 30
---

apiVersion: keda.k8s.io/v1alpha1
kind: ScaledObject
metadata:
  name: xyz-test-scaler-dev
  labels:
    app: xyz-test
    deploymentName: xyz-test
spec:
  scaleTargetRef:
    deploymentName: xyz-test
  minReplicaCount: 0
  maxReplicaCount: 3
  pollingInterval: 1
  triggers:
  - type: azure-servicebus
    metadata:
      # Required
      topicName: am-removal-test
      subscriptionName: am-subs
      namespace: iot-sbus-rc
      # Optional, can use TriggerAuthentication as well
      connection: feedbackServiceBusConnectionString
      # This must be a connection string for a queue itself, and not a namespace level (e.g. RootAccessPolicy) connection string [#215](https://github.com/kedacore/keda/issues/215)
      # Optional
      queueLength: &quot;2&quot;
    authenticationRef:
      name: azure-servicebus-auth
---
</code></pre>
<p>Getting error :</p>
<pre><code>Conditions:
  Type           Status  Reason                   Message
  ----           ------  ------                   -------
  AbleToScale    True    SucceededGetScale        the HPA controller was able to get the target's current scale
  ScalingActive  False   FailedGetExternalMetric  the HPA was unable to compute the replica count: unable to get external metric iots-dev/queueLength/&amp;LabelSelector{MatchLabels:map[string]string{deploymentName: xyz,},MatchExpressions:[]LabelSelectorRequirement{},}: unable to fetch metrics from external metrics API: the server is currently unable to handle the request (get queueLength.external.metrics.k8s.io)
Events:
  Type     Reason                   Age                       From                       Message
  ----     ------                   ----                      ----                       -------
  Warning  FailedGetExternalMetric  2m17s (x2591 over 5h53m)  horizontal-pod-autoscaler  unable to get external metric iots-dev/queueLength/&amp;LabelSelector{MatchLabels:map[string]string{deploymentName: xyz,},MatchExpressions:[]LabelSelectorRequirement{},}: unable to fetch metrics from external metrics API: the server is currently unable to handle the request (get queueLength.external.metrics.k8s.io)
</code></pre>
<p>After running command :</p>
<pre><code>```
</code></pre>
<p>apiVersion: apiregistration.k8s.io/v1</p>
<p>166kind: APIService</p>
<p>167metadata:</p>
<p>168 annotations:</p>
<p>169 kubectl.kubernetes.io/last-applied-configuration: |</p>
<p>170 {&quot;apiVersion&quot;:&quot;apiregistration.k8s.io/v1beta1&quot;,&quot;kind&quot;:&quot;APIService&quot;,&quot;metadata&quot;:{&quot;annotations&quot;:{},&quot;name&quot;:&quot;v1beta1.external.metrics.k8s.io&quot;},&quot;spec&quot;:{&quot;group&quot;:&quot;external.metrics.k8s.io&quot;,&quot;groupPriorityMinimum&quot;:100,&quot;insecureSkipTLSVerify&quot;:true,&quot;service&quot;:{&quot;name&quot;:&quot;custom-metrics-azure-apiserver&quot;,&quot;namespace&quot;:&quot;custom-metrics&quot;},&quot;version&quot;:&quot;v1beta1&quot;,&quot;versionPriority&quot;:100}}</p>
<p>171 creationTimestamp: &quot;2020-09-15T15:48:18Z&quot;</p>
<p>172 name: v1beta1.external.metrics.k8s.io</p>
<p>173 resourceVersion: &quot;13008780&quot;</p>
<p>174 selfLink: /apis/apiregistration.k8s.io/v1/apiservices/v1beta1.external.metrics.k8s.io</p>
<p>175 uid: a6a72678-001f-4378-ba10-cbff7d8c0ad2</p>
<p>176spec:</p>
<p>177 group: external.metrics.k8s.io</p>
<p>178 groupPriorityMinimum: 100</p>
<p>179 insecureSkipTLSVerify: true</p>
<p>180 service:</p>
<p>181 name: custom-metrics-azure-apiserver</p>
<p>182 namespace: custom-metrics</p>
<p>183 port: 443</p>
<p>184 version: v1beta1</p>
<p>185 versionPriority: 100</p>
<p>186status:</p>
<p>187 conditions:</p>
<p>188 - lastTransitionTime: &quot;2020-10-27T12:19:19Z&quot;</p>
<p>189 message: service/custom-metrics-azure-apiserver in &quot;custom-metrics&quot; is not present</p>
<p>190 reason: ServiceNotFound</p>
<p>191 status: &quot;False&quot;</p>
<p>192 type: Available</p>
<pre><code></code></pre>

<p>So, my working example of KEDA autoscaler with rabbitmq:</p>
<pre><code>apiVersion: keda.k8s.io/v1alpha1
kind: ScaledObject
metadata:
  name: job-export-autoscaler
  namespace: thor
spec:
  scaleTargetRef:
    deploymentName: job-export
  pollingInterval: 5 # Time after each check
  minReplicaCount: 0   # Optional. Default: 0
  maxReplicaCount: 10 # Optional. Default: 100
  cooldownPeriod: 60 # Cooldown since last trigger to outoscale down
  triggers:
  - type: rabbitmq
    metadata:
      queueName: report-export
      queueLength: &quot;1&quot;
    authenticationRef:
      name: trigger-auth-rabbitmq
</code></pre>
<p>Now the triggerAuth mentioned in the comments:</p>
<pre><code>apiVersion: keda.k8s.io/v1alpha1
kind: TriggerAuthentication
metadata:
  name: trigger-auth-rabbitmq
  namespace: thor
spec:
  secretTargetRef:
  - parameter: host
    name: rabbitmq-host-secret
    key: rabbitmq-connectionstring
---
apiVersion: v1
kind: Secret
metadata:
  name: rabbitmq-host-secret
  namespace: thor
  labels:
    app: rabbitmq
data:
  rabbitmq-connectionstring: (base64 encoded rabbitmq connection string)
</code></pre>
<p>So, for using Azure service bus:</p>
<p>Documentation: <a href="https://keda.sh/docs/1.4/scalers/azure-service-bus/#authentication-parameters" rel="nofollow noreferrer">https://keda.sh/docs/1.4/scalers/azure-service-bus/#authentication-parameters</a></p>
<p>Example:</p>
<pre><code>apiVersion: keda.k8s.io/v1alpha1
kind: TriggerAuthentication
metadata:
  name: azure-servicebus-auth
spec:
  podIdentity:
    provider: azure
---
apiVersion: keda.k8s.io/v1alpha1
kind: ScaledObject
metadata:
  name: azure-servicebus-queue-scaledobject
  namespace: default
spec:
  scaleTargetRef:
    deploymentName: azure-servicebus-queue-function
  triggers:
  - type: azure-servicebus
    metadata:
      # Required: queueName OR topicName and subscriptionName
      queueName: functions-sbqueue
      # or
      topicName: functions-sbtopic
      subscriptionName: sbtopic-sub1
      # Required: Define what Azure Service Bus to authenticate to with Managed Identity
      namespace: service-bus-namespace
      # Optional
      queueLength: &quot;5&quot; # default 5
    authenticationRef:
        name: azure-servicebus-auth # authenticationRef would need either podIdentity or define a connection parameter
</code></pre>
<p>So, you are missing the TriggerAuthentication object with the connection string</p>
