openfaas deployment.kubernetes.io/max-replicas 对比 com.openfaas.scale.max

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

我有一个 k8s 集群,我通过以下方式在其上安装了 openfaas:

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

现在,我有以下 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

部署的函数然后用我在 openfaas documentation 中找到的上述标签装饰。但是,如果我查看控制函数 pod 的副本集,我会看到它装饰有以下注释:

deployment.kubernetes.io/max-replicas=2

后一个注释对函数副本集的实际函数缩放有何影响?如果我设置

会发生什么
com.openfaas.scale.max: 3

作为我函数的标签?

我想确保真正控制我的函数的水平缩放。我该如何进行?

OpenFaas 本身配备了自动缩放器和自己的警报管理器:

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.

经过一些阅读,我发现 OpenFaas autoscaler/alertmanger 更关注 API 命中率,而 Kubernetes HPA 更关注 CPU 和内存使用,所以这完全取决于什么你确实需要。

因此,对于两种不同的缩放工具,您有两种不同的注释。 deployment.kubernetes.io/max-replicas=2 用于 Kubernetes HPA,com.openfaas.scale.max: 1 用于 OpenFaas 自动缩放器。

OpenFaas 有一个很棒的example of how you can use HPA instead built in scaler. You can also use custom Prometheus metrics with HPA as described here