Skip to content

Scaling Policy

A scaling policy is a set of rules that allows you to perform scaling actions on targets based on triggers. For example cron based trigger supports dynamic configuration of ScaledObjects and ScaledJobs based on the time and day.

Targets

A target is a reference to a resource that you want to apply the scaling policy to. Scaling policy supports only targets in the same namespace.

Supported targets are:

  • ScaledObject
  • ScaledJob

Actions

An action is a set of rules that define when and how to scale the target. trigger defines when the action should be executed and adjustment defines how the target should be scaled.

Triggers:

At the moment a trigger based on the a cron schedule is supported, the schedule expets Linux format cron (Minute Hour DayOfMonth Month DayOfWeek).

  • schedule: A cron-like trigger that defines when the action should be executed with the following fields:
    • start: The start time of the schedule. For example 30 6 * * *, at 06:30 AM.
    • end: The end time of the schedule. For example 0 14 * * *, at 02:00 PM.
    • timezone: The timezone of the schedule. For example Europe/Prague.

Adjustments:

The following adjustments are supported:

  • pollingInterval: The interval in seconds at which the target should be polled.
  • idleReplicaCount: The number of replicas to scale down to when the target is idle (not supported by ScaledJobs).
  • minReplicaCount: The minimum number of replicas the target should have.
  • maxReplicaCount: The maximum number of replicas the target should have.
  • pausedConfig: Paused related settings.
    • paused: Scaling will paused for a target (ScaledObject or ScaledJob).
    • replicas: Scaling will paused at the specific number of replicas for a target (only ScaledObject is supported).

Example adjustment:

adjustment:
pollingInterval: 10
idleReplicaCount: 0
minReplicaCount: 5
maxReplicaCount: 99
pauseConfig:
replicas: 0
paused: true

You can define overlapping actions with different priorities and the adjustment parameters will get merged with the lowest positive integer having the highest priority.

Creating a Scaling Policy

Example Scaling Policy where the target is a ScaledObject named sample-so and a ScaledJob sample-sj and it has three actions:

  • day: Scale the target between 06:30 AM and 02:00 PM to a minimum of 5 replicas and a maximum of 10 replicas.
  • night: Scale the target between 06:00 PM and 06:00 AM to a minimum of 0 replicas and a maximum of 2 replicas.
  • peak: Scale the target between 09:00 AM and 11:00 AM to a minimum of 10 replicas and a maximum of 15 replicas. This action has a higher priority than the other two actions.
apiVersion: keda.kedify.io/v1alpha1
kind: ScalingPolicy
metadata:
name: scalingpolicy-sample
spec:
targets:
- apiVersion: 'keda.sh/v1alpha1'
kind: ScaledObject
name: sample-so
- apiVersion: 'keda.sh/v1alpha1'
kind: ScaledJob
name: sample-sj
actions:
- name: day
priority: 2
trigger:
schedule:
start: '30 6 * * *'
end: '0 14 * * *'
timezone: 'Europe/Prague'
adjustment:
minReplicaCount: 5
maxReplicaCount: 10
- name: night
priority: 2
trigger:
schedule:
start: '0 18 * * *'
end: '0 6 * * *'
timezone: 'Europe/Prague'
adjustment:
minReplicaCount: 0
maxReplicaCount: 2
- name: peak
priority: 1
trigger:
schedule:
start: '0 9 * * *'
end: '0 11 * * *'
timezone: 'Europe/Prague'
adjustment:
minReplicaCount: 10
maxReplicaCount: 15