Pausing the custom metrics autoscaler for a scaled object

You can pause and restart the autoscaling of a workload, as needed.

For example, you might want to pause autoscaling before performing cluster maintenance or to avoid resource starvation by removing non-mission-critical workloads.

Pausing a custom metrics autoscaler

You can pause the autoscaling of a scaled object by adding the autoscaling.keda.sh/paused-replicas annotation to the custom metrics autoscaler for that scaled object. The custom metrics autoscaler scales the replicas for that workload to the specified value and pauses autoscaling until the annotation is removed.

  1. apiVersion: keda.sh/v1alpha1
  2. kind: ScaledObject
  3. metadata:
  4. annotations:
  5. autoscaling.keda.sh/paused-replicas: "4"
  6. # ...

Procedure

  1. Use the following command to edit the ScaledObject CR for your workload:

    1. $ oc edit ScaledObject scaledobject
  2. Add the autoscaling.keda.sh/paused-replicas annotation with any value:

    1. apiVersion: keda.sh/v1alpha1
    2. kind: ScaledObject
    3. metadata:
    4. annotations:
    5. autoscaling.keda.sh/paused-replicas: "4" (1)
    6. creationTimestamp: "2023-02-08T14:41:01Z"
    7. generation: 1
    8. name: scaledobject
    9. namespace: my-project
    10. resourceVersion: '65729'
    11. uid: f5aec682-acdf-4232-a783-58b5b82f5dd0
    1Specifies that the Custom Metrics Autoscaler Operator is to scale the replicas to the specified value and stop autoscaling.

Restarting the custom metrics autoscaler for a scaled object

You can restart a paused custom metrics autoscaler by removing the autoscaling.keda.sh/paused-replicas annotation for that ScaledObject.

  1. apiVersion: keda.sh/v1alpha1
  2. kind: ScaledObject
  3. metadata:
  4. annotations:
  5. autoscaling.keda.sh/paused-replicas: "4"
  6. # ...

Procedure

  1. Use the following command to edit the ScaledObject CR for your workload:

    1. $ oc edit ScaledObject scaledobject
  2. Remove the autoscaling.keda.sh/paused-replicas annotation.

    1. apiVersion: keda.sh/v1alpha1
    2. kind: ScaledObject
    3. metadata:
    4. annotations:
    5. autoscaling.keda.sh/paused-replicas: "4" (1)
    6. creationTimestamp: "2023-02-08T14:41:01Z"
    7. generation: 1
    8. name: scaledobject
    9. namespace: my-project
    10. resourceVersion: '65729'
    11. uid: f5aec682-acdf-4232-a783-58b5b82f5dd0
    1Remove this annotation to restart a paused custom metrics autoscaler.