如何根据另一个部署产生的指标使HPA扩展一个部署

Tim*_*Tim 5 horizontal-scaling kubernetes

我要实现的目标是创建一个能够worker根据Pod 生成的自定义指标缩放Pod的Horizo​​ntal Pod Autoscaler controller

我已经使Prometheus抓取,Prometheus Adapater,Custom Metric Server完全运行,并且已经worker使用了my_controller_metricworkerpod 生成的自定义指标来扩展部署。

现在,我的广告worker连播不再产生此指标,但实际产生了controller。似乎API autoscaling / v1不支持此功能。如果需要,我可以使用autoscaling / v2beta1 API指定HPA。

这是我对此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
Run Code Online (Sandbox Code Playgroud)

当应用配置时,kubectl apply -f my-worker-hpa.yml我收到消息:

horizontalpodautoscaler "my-worker-hpa" configured
Run Code Online (Sandbox Code Playgroud)

尽管此消息似乎还可以,但是HPA无法正常工作。这个规格格式不正确吗?

就像我说的那样,该指标可在Custom Metric Server中使用kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1" | jq . | grep my_controller_metric

这是来自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
Run Code Online (Sandbox Code Playgroud)

谢谢!

Pjo*_*erS 0

在您的情况下,问题是 HPA 配置:spec.metrics.object.target还应该指定 API 版本。放在apiVersion: extensions/v1beta1下面spec.metrics.object.target应该可以修复它。

此外,还有一个关于 HPA 中更好的配置验证的开放问题: https: //github.com/kubernetes/kubernetes/issues/60511