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

时间:2019-03-29 09:08:02

标签: kubernetes horizontal-scaling

我要实现的目标是创建一个水平Pod自动缩放器,该缩放器能够根据worker容器产生的自定义指标来缩放controller容器。

我已经使Prometheus抓取,Prometheus Adapater,Custom Metric Server完全运行,并使用worker窗格生成的自定义指标my_controller_metric扩展worker部署,已经可以使用。

现在,我的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

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

horizontalpodautoscaler "my-worker-hpa" configured

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

正如我所说,该指标在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

谢谢!

1 个答案:

答案 0 :(得分:0)

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

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