Scale to Zero

OpenFaaS PRO offers an additional component that can be used to scale idle functions to zero replicas. When scaled to zero, functions do not consume CPU or memory, and are then scaled back to the minimum desired amount of replicas upon first use.

Installation

You can enable Scale to Zero using arkade or helm.

Learn how to enable Scale to Zero using the helm chart.

Usage

Once enabled in your cluster, you can opt functions into being scaled to zero by adding the following label to stack.yml.

Create a new function:

  1. export OPENFAAS_PREFIX=ghcr.io/openfaas
  2. faas-cli new --lang go daily-job

Now add the labels:

  1. version: 1.0
  2. provider:
  3. name: openfaas
  4. gateway: http://127.0.0.1:8080
  5. functions:
  6. daily-job:
  7. labels:
  8. com.openfaas.scale.zero: true
  9. lang: go
  10. handler: ./daily-job
  11. image: ghcr.io/openfaas:daily-job

Once you have deployed and invoked your function, you should see it start to appear in the logs:

  1. kubectl logs -n openfaas deploy/faas-idler -f

Open another terminal to monitor the replicas of your function:

  1. kubectl get -n openfaas-fn deploy/daily-job -w

After the chosen scale to zero period, you will see its replicas scale to zero.

Then, you can invoke the function and you’ll see the function scale up and get invoked again:

  1. echo | faas-cli invoke daily-job

You can learn more about OpenFaaS auto-scaling here: autoscaling