kedacore / keda

KEDA is a Kubernetes-based Event Driven Autoscaling component. It provides event driven scale for any container running in Kubernetes
https://keda.sh
Apache License 2.0
8.28k stars 1.05k forks source link

ScaledObject downscales deployment to 0 replicas outside specified timeframe in cron trigger even when cpu trigger should keep it running #6057

Open JuniorJPDJ opened 1 month ago

JuniorJPDJ commented 1 month ago

Report

On time XX:33 it starts, when cpu is being used it scales up, but then even if more than 1 replicas are here on XX:55 its just scaling it all down to 0 replicas.

The ScaledObject:

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: <REDACTED>
  namespace: <REDACTED>
spec:
  advanced:
    horizontalPodAutoscalerConfig:
      behavior:
        scaleDown:
          policies:
          - periodSeconds: 15
            type: Percent
            value: 100 
          stabilizationWindowSeconds: 300 
    restoreToOriginalReplicaCount: true
    scalingModifiers: {}
  cooldownPeriod: 10
  maxReplicaCount: 3
  minReplicaCount: 0
  pollingInterval: 30
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: <REDACTED>
  triggers:
  - metadata:
      value: "70"
    metricType: Utilization
    type: cpu
  - metadata:
      desiredReplicas: "1"
      end: 55 * * * *
      start: 33 * * * *
      timezone: Etc/UTC
    type: cron

Expected Behavior

After reading this: https://keda.sh/docs/2.13/reference/faq/#using-multiple-triggers-for-the-same-scale-target It seems like the deployment shouldn't scale down until the CPU trigger is keeping it up. It should only downscale to 0 when there is low CPU usage and we are not inside timeframe defined for cron trigger.

Actual Behavior

After timeframe of cron trigger is over, instantly deployment scales down to 0.

Steps to Reproduce the Problem

  1. Setup the SO like mine or similar.
  2. Run some CPU-intensive task (like sha1sum /dev/zero) inside a pod and wait it to scale up.
  3. Wait for timeframe of cron trigger to be over

Logs from KEDA operator

No response

KEDA Version

2.13.1

Kubernetes Version

1.29

Platform

Amazon Web Services

Scaler Details

cpu, cron

Anything else?

No response

JuniorJPDJ commented 1 month ago

This is similar or duplicate to #5620 which is closed due to inactivity

kunwooy commented 5 hours ago

This issue is very difficult to solve with the current implementation of CPU scaler. The biggest problem is that resource-metrics based scalers (like CPU and memory) do not have activationThreshold field which is crucial for determining whether the deployment should be scaled to zero or not.