问题描述
我有一个 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 附带在挂载文件中定义的单个自动缩放规则 AlertManager 的配置文件。 AlertManager 读取使用情况 (每秒请求数)来自 Prometheus 的指标,以便了解何时 向 API 网关发出警报。
经过一些阅读,我发现 OpenFaas autoscaler/alertmanger 更关注 API 命中率,而 Kubernetes HPA 更关注 CPU 和内存使用,因此这完全取决于您的确切需求。
因此,对于两种不同的缩放工具,您有两种不同的注释。
deployment.kubernetes.io/max-replicas=2
用于 Kubernetes HPA,com.openfaas.scale.max: 1
用于 OpenFaas 自动缩放器。
OpenFaas 有一个很好的example 说明如何使用 HPA 而不是内置的缩放器。您还可以将自定义 Prometheus 指标与 HPA 结合使用,如here 所述。