Does PodDisruptionBudget prevent KEDA ScaledObject from scaling down?

32 Views Asked by At

I have a Deployment and PDB (PodDisruptionBudget) that forces minAvailable: 1. I created a KEDA ScaledObject that should scaled to 0 based on a given time windows using the KEDA Cron Scaler

---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  annotations: {}
  name: nginx-deployment
  namespace: rubentest
spec:
  advanced:
    horizontalPodAutoscalerConfig:
      behavior:
        scaleDown:
          stabilizationWindowSeconds: 30
  idleReplicaCount: 0
  maxReplicaCount: 7
  minReplicaCount: 0
  scaleTargetRef:
    name: nginx-deployment
  triggers:
    - metadata:
        desiredReplicas: "0"
        start: 44 * * * *
        end: 45 * * * *
        timezone: Europe/Stockholm
      type: cron

But this does seem to work. At the start of time window, the deployment is scaled to 1 (ignoring the desiredReplicas: "0").

I guess it's the PDB that interferes with it. Is that the case?

1

There are 1 best solutions below

0
RubenLaguna On

From this keda issue comment on the subject:

KEDA doesn't respect PDB and it doesn't have to respect it as the PDB is for draining operations. I mean, Karpenter has to respect the PDB when it drains the node, but KEDA can (and it does) scale to 0 the workload although the PDB says no.

So KEDA does not look at the PDB and it will update the .spec.replicas to 0 in the Deployment regardless of what the PDB says. And there is nothing in vanilla Kubernetes that will prevent KEDA from doing that. In the same way that there is nothing preventing you from updating the .spec.replicas manually with kubectl.

In the same note, nothing in vanilla Kubernetes will restore the .spec.replicas to 1. Specifically the HorizontalPodAutoscaler HPA disables itself when replicas are set to 0.

The fact that your Deployment is scaled to 1 when desiredReplicas: 0 is not due to interaction with PodDisruptionBudget.

In this case you need to rewrite the ScaledObject and write instead the time window where you want to scale up see this issue. For example, the following scales the Deployment to 5 replicas during office hours (6AM to 8PM) and scales down to 0 outside that time range:

---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
...
spec:
  ...
  minReplicaCount: 0
...
  triggers:
    - metadata:
        desiredReplicas: "5"
        start: "0 6 * * *" # scale to 5 from 6AM 
        end: "0 20 * * *"  # to 8PM, it gets to 0 outside this window
        timezone: Europe/Stockholm
      type: cron