Use external scalers

This tutorial shows how to use an external resource scaler, for example, HorizontalPodAutoscaler (HPA) or Keda's ScaledObject, with the Serverless Function.

Keep in mind that the Serverless Functions implement the scale subresource, which means that you can use any Kubernetes-based scaler.

Prerequisites

Before you start, make sure you have these tools installed:

Steps

Follow these steps:

  • HPA
  • Keda CPU
  • Keda Prometheus
  1. Create your Function with the replicas value set to 1, to prevent the internal Serverless HPA creation:

    Click to copy
    cat <<EOF | kubectl apply -f -
    apiVersion: serverless.kyma-project.io/v1alpha2
    kind: Function
    metadata:
    name: scaled-function
    spec:
    runtime: nodejs16
    replicas: 1
    source:
    inline:
    dependencies: ""
    source: |
    module.exports = {
    main: function(event, context) {
    return 'Hello World!'
    }
    }
    EOF
  2. Create your HPA using kubectl:

    Click to copy
    kubectl autoscale function scaled-function --cpu-percent=50 --min=5 --max=10
  3. After a few seconds your HPA should be up to date and contain information about the actual replicas:

    Click to copy
    kubectl get hpa scaled-function

    You should get a result similar to this example:

    Click to copy
    NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
    scaled-function Function/scaled-function 1%/50% 5 10 5 61s