kuberneteskeda

Failure while deploying a KEDA ScaledObject


On a minikube I have installed KEDA and managed to scale up/down a small service I have created using the Postgres scaler.

After a while, the scaler stopped working, and I don't understand why.

Here's the spec from the ScaledObject yaml:

spec:
    minReplicaCount: 0
    maxReplicaCount: 5
    pollingInterval: 30
    cooldownPeriod: 30
    scaleTargetRef:
        name: demo-service
    triggers:
        -   type: postgresql
            metadata:
                connection: "postgresql://host.minikube.internal:5432"
                userName: "postgres"
                passwordFromEnv: demo-service-secret-keda-password
                host: "host.minikube.internal"
                dbName: "postgres"
                sslmode: disable
                port: "5432"
                query: "select value from keda where id = 1"
                targetQueryValue: "3"

Postgres is running on Docker on the same machine, and here's the result of the query:

postgres=# select value from keda where id = 1;                                                                                                                      value 
-------
     2
(1 row)

Looking at the logs of the Keda pod, I see:

2022-11-07T14:48:59Z    ERROR   Reconciler error    {"controller": "scaledobject", "controllerGroup": "keda.sh", "controllerKind": "ScaledObject", "scaledObject": {"name":"postgres-scaledobject","namespace":"default"}, "namespace": "default", "name": "postgres-scaledobject", "reconcileID": "06cbd2e8-93ac-43a1-8cf0-ac4852eac4be", "error": "HorizontalPodAutoscaler.autoscaling \"keda-hpa-postgres-scaledobject\" is invalid: spec.metrics[0].external.target.averageValue: Invalid value: resource.Quantity{i:resource.int64Amount{value:0, scale:0}, d:resource.infDecAmount{Dec:(*inf.Dec)(nil)}, s:\"0\", Format:\"DecimalSI\"}: must be positive"}

But I don't understand the error, because the value IS positive. I did set it at one point to a negative value, but I have changed it multiple times since, and I have undeployed the ScaledObject and redeployed it.

I am not sure how to fix this, so any help is welcome.

Thanks.


Solution

  • Uninstalling and installing KEDA in my cluster helped.

    kubectl delete -f https://github.com/kedacore/keda/releases/download/v2.9.0/keda-2.9.0.yaml

    kubectl apply --server-side -f https://github.com/kedacore/keda/releases/download/v2.9.0/keda-2.9.0.yaml

    I suppose that if you change the targetvalue of your trigger to something invalid it does not get deleted when you delete the ScaledObject somehow.