kuberneteshpaopenfaas

openfaas deployment.kubernetes.io/max-replicas vs com.openfaas.scale.max


I have a k8s cluster on which I have installed openfaas in the following way:

helm repo add openfaas https://openfaas.github.io/faas-netes/
helm repo update

kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml

helm upgrade openfaas --install openfaas/openfaas \
  --namespace openfaas \
  --set generateBasicAuth=true \
  --set serviceType=LoadBalancer \
  --set clusterRole=true \
  --set functionNamespace=openfaas-fn

Now, I have the following stack.yml:

version: 1.0
provider:
  name: openfaas
  gateway: http://localhost:31112
functions:
  my-function:
    lang: csharp
    handler: ./MyFunction
    image: my-function:my-tag
    labels:
      com.openfaas.scale.min: 1
      com.openfaas.scale.max: 1
      com.openfaas.scale.factor: 0

The deployed function is then decorated with the above mentioned labels, which I found in the openfaas documentation. However, if I look at the replica set controlling the function's pod, I see it is adorned with the following annotation:

deployment.kubernetes.io/max-replicas=2

What is the effect of this latter annotation on the function's replica set over the actual function's scaling? What would happen if I set

com.openfaas.scale.max: 3

as my function's label?

I would like to make sure to really have control over my function's horizontal scaling. How should I proceed?


Solution

  • The OpenFaas is equiped with autoscaler itself with its own alert manager:

    OpenFaaS ships with a single auto-scaling rule defined in the mounted configuration file for AlertManager. AlertManager reads usage (requests per second) metrics from Prometheus in order to know when to fire an alert to the API Gateway.

    After some reading I found out that OpenFaas autoscaler/alertmanger is more focused on API hit rates whereas Kubernetes HPA is more focused on CPU and memory usage so it all depends on what you exactly need.

    So you have two different annotations for two different tools for scaling. The deployment.kubernetes.io/max-replicas=2 is for Kubernetes HPA and com.openfaas.scale.max: 1 is for the OpenFaas autoscaler.

    The OpenFaas has a great example of how you can use HPA instead built in scaler. You can also use custom Prometheus metrics with HPA as described here.