Supported Autoscaler types

Knative Serving supports the implementation of Knative Pod Autoscaler (KPA) and Kubernetes’ Horizontal Pod Autoscaler (HPA). This topic lists the features and limitations of each of these Autoscalers, as well as how to configure them.

Important

If you want to use Kubernetes Horizontal Pod Autoscaler (HPA), you must install it after you install Knative Serving.

For how to install HPA, see Install optional Serving extensions.

Knative Pod Autoscaler (KPA)

  • Part of the Knative Serving core and enabled by default once Knative Serving is installed.
  • Supports scale to zero functionality.
  • Does not support CPU-based autoscaling.

Horizontal Pod Autoscaler (HPA)

  • Not part of the Knative Serving core, and you must install Knative Serving first.
  • Does not support scale to zero functionality.
  • Supports CPU-based autoscaling.

Configuring the Autoscaler implementation

The type of Autoscaler implementation (KPA or HPA) can be configured by using the class annotation.

  • Global settings key: pod-autoscaler-class
  • Per-revision annotation key: autoscaling.knative.dev/class
  • Possible values: "kpa.autoscaling.knative.dev" or "hpa.autoscaling.knative.dev"
  • Default: "kpa.autoscaling.knative.dev"

Example:

Per RevisionGlobal (ConfigMap)Global (Operator)

  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/class: "kpa.autoscaling.knative.dev"
  11. spec:
  12. containers:
  13. - image: ghcr.io/knative/helloworld-go:latest
  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-autoscaler
  5. namespace: knative-serving
  6. data:
  7. pod-autoscaler-class: "kpa.autoscaling.knative.dev"
  1. apiVersion: operator.knative.dev/v1alpha1
  2. kind: KnativeServing
  3. metadata:
  4. name: knative-serving
  5. spec:
  6. config:
  7. autoscaler:
  8. pod-autoscaler-class: "kpa.autoscaling.knative.dev"

Global versus per-revision settings

Configuring for autoscaling in Knative can be set using either global or per-revision settings.

  1. If no per-revision autoscaling settings are specified, the global settings will be used.
  2. If per-revision settings are specified, these will override the global settings when both types of settings exist.

Global settings

Global settings for autoscaling are configured using the config-autoscaler ConfigMap. If you installed Knative Serving using the Operator, you can set global configuration settings in the spec.config.autoscaler ConfigMap, located in the KnativeServing custom resource (CR).

Example of the default autoscaling ConfigMap
  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-autoscaler
  5. namespace: knative-serving
  6. data:
  7. container-concurrency-target-default: "100"
  8. container-concurrency-target-percentage: "0.7"
  9. enable-scale-to-zero: "true"
  10. max-scale-up-rate: "1000"
  11. max-scale-down-rate: "2"
  12. panic-window-percentage: "10"
  13. panic-threshold-percentage: "200"
  14. scale-to-zero-grace-period: "30s"
  15. scale-to-zero-pod-retention-period: "0s"
  16. stable-window: "60s"
  17. target-burst-capacity: "200"
  18. requests-per-second-target-default: "200"

Per-revision settings

Per-revision settings for autoscaling are configured by adding annotations to a revision.

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/target: "70"

Important

If you are creating revisions by using a service or configuration, you must set the annotations in the revision template so that any modifications will be applied to each revision as they are created. Setting annotations in the top level metadata of a single revision will not propagate the changes to other revisions and will not apply changes to the autoscaling configuration for your application.