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?
From this keda issue comment on the subject:
So KEDA does not look at the PDB and it will update the
.spec.replicasto 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.replicasmanually withkubectl.In the same note, nothing in vanilla Kubernetes will restore the
.spec.replicasto 1. Specifically the HorizontalPodAutoscaler HPA disables itself when replicas are set to 0.The fact that your Deployment is scaled to 1 when
desiredReplicas: 0is 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: