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:
- Kyma installed on a cluster
Steps
Follow these steps:
- HPA
- Keda CPU
- Keda Prometheus
Create your Function with the
replicas
value set to 1, to prevent the internal Serverless HPA creation:Click to copycat <<EOF | kubectl apply -f -apiVersion: serverless.kyma-project.io/v1alpha2kind: Functionmetadata:name: scaled-functionspec:runtime: nodejs16replicas: 1source:inline:dependencies: ""source: |module.exports = {main: function(event, context) {return 'Hello World!'}}EOFCreate your HPA using kubectl:
Click to copykubectl autoscale function scaled-function --cpu-percent=50 --min=5 --max=10After a few seconds your HPA should be up to date and contain information about the actual replicas:
Click to copykubectl get hpa scaled-functionYou should get a result similar to this example:
Click to copyNAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGEscaled-function Function/scaled-function 1%/50% 5 10 5 61s