如何根据另一个部署产生的指标使HPA扩展一个部署 [英] How to make HPA scale a deployment based on metrics produced by another deployment
问题描述
我要实现的目标是创建一个水平容器自动缩放器,该缩放器能够根据 controller
容器生成的自定义指标来缩放 worker
容器.
What I am trying to achieve is creating a Horizontal Pod Autoscaler able to scale worker
pods according to a custom metric produced by a controller
pod.
我已经拥有Prometheus抓取,Prometheus Adapater,Custom Metric Server完全可操作,并使用由 worker产生的自定义指标
my_controller_metric
扩展了 worker
部署code>豆荚已经可以使用了.
I already have Prometheus scraping, Prometheus Adapater, Custom Metric Server fully operational and scaling the worker
deployment with a custom metric my_controller_metric
produced by the worker
pods already works.
现在,我的 worker
pods不再产生此指标,但 controller
会产生.似乎API autoscaling/v1不支持此功能.如有必要,我可以使用autoscaling/v2beta1 API来指定HPA.
Now my worker
pods don't produce this metric anymore, but the controller
does.
It seems that the API autoscaling/v1 does not support this feature. I am able to specify the HPA with the autoscaling/v2beta1 API if necessary though.
这是我对此HPA的规格:
Here is my spec for this HPA:
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: my-worker-hpa
namespace: work
spec:
maxReplicas: 10
minReplicas: 1
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: my-worker-deployment
metrics:
- type: Object
object:
target:
kind: Deployment
name: my-controller-deployment
metricName: my_controller_metric
targetValue: 1
当使用 kubectl应用配置时,应用-f my-worker-hpa.yml
我得到消息:
horizontalpodautoscaler "my-worker-hpa" configured
尽管此消息似乎还可以,但是HPA无法正常工作.这个规范格式不正确吗?
Though this message seems to be OK, the HPA does not work. Is this spec malformed?
正如我所说,该度量标准在Custom Metric Server中可用,代码为 kubectl get --raw"/apis/custom.metrics.k8s.io/v1beta1" |jq.|grep my_controller_metric
.
As I said, the metric is available in the Custom Metric Server with a kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1" | jq . | grep my_controller_metric
.
这是HPA的错误消息:
This is the error message from the HPA:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True SucceededGetScale the HPA controller was able to get the target's current scale
ScalingActive False FailedGetObjectMetric the HPA was unable to compute the replica count: unable to get metric my_controller_metric: Deployment on work my-controller-deployment/unable to fetch metrics from custom metrics API: the server could not find the metric my_controller_metric for deployments
谢谢!
推荐答案
在您的情况下,问题是HPA配置: spec.metrics.object.target
也应指定API版本.将 apiVersion:extensions/v1beta1
放在 spec.metrics.object.target
下应该可以解决此问题.
In your case problem is HPA configuration: spec.metrics.object.target
should also specify API version.
Putting apiVersion: extensions/v1beta1
under spec.metrics.object.target
should fix it.
此外,关于HPA中更好的配置验证,还有一个未解决的问题: https://github.com/kubernetes/kubernetes/issues/60511
In addition, there is an open issue about better config validation in HPA: https://github.com/kubernetes/kubernetes/issues/60511
这篇关于如何根据另一个部署产生的指标使HPA扩展一个部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!