Configuring scale to zero

IMPORTANT: Scale to zero can only be enabled if you are using the Knative Pod Autoscaler (KPA), and can only be configured globally. For more information about using KPA or global configuration, see the documentation on Autoscaling concepts.

Enable scale to zero

The scale to zero value controls whether Knative allows replicas to scale down to zero (if set to true), or stop at 1 replica if set to false.

NOTE: For more information about scale bounds configuration per revision, see the documentation on Configuring scale bounds.

  • Global key: enable-scale-to-zero
  • Per-revision annotation key: No per-revision setting.
  • Possible values: boolean
  • Default: true

Example:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-autoscaler
  5. namespace: knative-serving
  6. data:
  7. enable-scale-to-zero: "false"
  1. apiVersion: operator.knative.dev/v1alpha1
  2. kind: KnativeServing
  3. metadata:
  4. name: knative-serving
  5. spec:
  6. config:
  7. autoscaler:
  8. enable-scale-to-zero: "false"

Scale to zero grace period

This setting specifies an upper bound time limit that the system will wait internally for scale-from-zero machinery to be in place before the last replica is removed.

IMPORTANT: This is a value that controls how long internal network programming is allowed to take, and should only be adjusted if you have experienced issues with requests being dropped while a revision was scaling to zero replicas.

This setting does not adjust how long the last replica will be kept after traffic ends, and it does not guarantee that the replica will actually be kept for this entire duration.

  • Global key: scale-to-zero-grace-period
  • Per-revision annotation key: n/a
  • Possible values: Duration
  • Default: 30s

Example:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-autoscaler
  5. namespace: knative-serving
  6. data:
  7. scale-to-zero-grace-period: "40s"
  1. apiVersion: operator.knative.dev/v1alpha1
  2. kind: KnativeServing
  3. metadata:
  4. name: knative-serving
  5. spec:
  6. config:
  7. autoscaler:
  8. scale-to-zero-grace-period: "40s"

Scale to zero last pod retention period

The scale-to-zero-pod-retention-period flag determines the minimum amount of time that the last pod will remain active after the Autoscaler decides to scale pods to zero.

This contrasts with the scale-to-zero-grace-period flag, which determines the maximum amount of time that the last pod will remain active after the Autoscaler decides to scale pods to zero.

  • Global key: scale-to-zero-pod-retention-period
  • Per-revision annotation key: autoscaling.knative.dev/scaleToZeroPodRetentionPeriod
  • Possible values: Non-negative duration string
  • Default: 0s

Example:

  1. apiVersion: serving.knative.dev/v1
  2. kind: Service
  3. metadata:
  4. name: helloworld-go
  5. namespace: default
  6. spec:
  7. template:
  8. metadata:
  9. annotations:
  10. autoscaling.knative.dev/scaleToZeroPodRetentionPeriod: "1m5s"
  11. spec:
  12. containers:
  13. - image: gcr.io/knative-samples/helloworld-go
  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-autoscaler
  5. namespace: knative-serving
  6. data:
  7. scale-to-zero-pod-retention-period: "42s"
  1. apiVersion: operator.knative.dev/v1alpha1
  2. kind: KnativeServing
  3. metadata:
  4. name: knative-serving
  5. spec:
  6. config:
  7. autoscaler:
  8. scale-to-zero-pod-retention-period: "42s"