2

I have a deployment.yaml of application with CPU and memory specified as :

resources:
        requests:
          memory: "10Gi"
          ephemeral-storage:  2Gi
          cpu: 50m
        limits:
          memory: "12Gi"
          ephemeral-storage:  5Gi
          cpu: 5

The KEDA scaling is defined as follows :

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: keda-scaler
  labels:
    app.kubernetes.io/name: app123
    infra.arc/repo.managed: kubernetes
spec:
  scaleTargetRef:
    name: app123
  cooldownPeriod: 60
  minReplicaCount: 2
  maxReplicaCount: 5
  advanced:
    restoreToOriginalReplicaCount: true
  fallback: # Fallback strategy when metrics are unavailable for the apps
    failureThreshold: 3 
    replicas: 2 #Keep this desired state when metrics are unavailable.
  triggers:
    - type: cpu 
      metadata:
        type: Utilization
        value: "80"

What the behavior is happening as soon i start the deployment it automaticaly scales to maxReplica

As per KEDA docs https://keda.sh/docs/2.7/scalers/cpu/

When using Utilization, the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods. When using AverageValue, the target value is the target value of the average of the metric across all relevant pods (quantity).

I could not get in this case i have set the value as 80% but still its scaling too early to max replicas.

Can anyone please suggest what is true meaning of value and metric type with respect to cpu and memory limits we give in deployment.yaml

1 Answer 1

0

The value from your example is CPU usage (1 CPU core = 1000m). For example this my ScaledObject for ingres

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: ingress-cpu-scaler
  namespace: ingress-nginx
spec:
  scaleTargetRef:
    name: ingress-nginx-controller
    kind: Deployment
    apiVersion: apps/v1
  fallback: # Fallback strategy when metrics are unavailable for the apps
    failureThreshold: 4 # Optional. Default: 3 
    replicas: 5 # Keep this desired state when metrics are unavailable.
  minReplicaCount: 3                                 # Optional. Default: 0
  maxReplicaCount: 16                                # Optional. Default: 100 
  triggers:
  - type: cpu
    metricType: Utilization # Allowed types are 'Utilization' or 'AverageValue'
    metadata:
      value: "180" # If the CPU usage more than 180m, then KEDA will start a new replica

Important: This scaler does not work if your deployment does not have limits and requests params.

1
  • The doc says "When using Utilization, the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods." So it's IMO pretty clear the value should be a percentage, not 'quantity'
    – mikus
    Commented Feb 27 at 13:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.