4

With plain HPAs it is possible to scale the underlying deployment manually to zero. This is required for eg. maintainance tasks. When scaling back to a value greater zero, the scaling continues as before. This is the command executed: kubectl scale deployment my-deployment --replicas=0

With KEDA however, this is not possible. The only place in the documentation states:

KEDA will not enforce that value, meaning you can manually scale the deployment to 0 and KEDA will not scale it back up. However, when KEDA itself is scaling the deployment it will respect the value set there.

I can not confirm this behaviour, nor does the previous scaling command works. Manually changing the minReplicas and maxReplicas to zero throws a lot of errors in the keda log, the same happens when pointing the deployment to an fake-value.

I need a way to scale to zero temporary (deleting the ScaledObject works of course, but then I need to store them somewhere, which is also errorprone and counterintuitive). This should work independant from the value of minReplicaCount.

Using Kubernetes 1.15, keda 1.5.0. Example ScaledObject:

apiVersion: keda.k8s.io/v1alpha1
kind: ScaledObject
metadata: ... # left out
spec:
  cooldownPeriod: 600
  maxReplicaCount: 8
  minReplicaCount: 0
  pollingInterval: 30
  scaleTargetRef:
    containerName: main
    deploymentName: my-deployment
  scaleType: deployment
  triggers:
  - type: kafka
    ... # left out
status:
  externalMetricNames:
  - lagThreshold
  lastActiveTime: "2020-07-21T11:32:31Z"
Dag
  • 10,079
  • 8
  • 51
  • 74

1 Answers1

0

Pretty late but hopefully will help some people like me who got here after few years...

Documentation of more recent versions of KEDA doesn't contain fragment that you mentioned. However, since KEDA 2.7, which was released in May 2022, you can pause autoscaling with autoscaling.keda.sh/paused-replicas annotation applied on ScaledObject. This annotation allows you to keep number of replicas constant (it can be any non-negative integer, not necessarily 0). So in case from question, you should just add autoscaling.keda.sh/paused-replicas: "0" line to YAML describing your ScaledObject so it would look like this:

apiVersion: keda.k8s.io/v1alpha1
kind: ScaledObject
metadata:
  annotations:
    autoscaling.keda.sh/paused-replicas: "0"
  ... # other annotations and metadata
spec:
  cooldownPeriod: 600
  maxReplicaCount: 8
  minReplicaCount: 0
  pollingInterval: 30
  scaleTargetRef:
    containerName: main
    deploymentName: my-deployment
  scaleType: deployment
  triggers:
  - type: kafka
    ... # left out
status:
  externalMetricNames:
  - lagThreshold
  lastActiveTime: "2020-07-21T11:32:31Z"

I tested it with KEDA 2.10.1 and K8s 1.26.4 and worked like a charm.

Here are relevant docs and KEDA release notes.

hnwoh
  • 128
  • 1
  • 10