1

请关于如何实现水平吊舱自动缩放的小问题

我有一个 SpringBoot 应用程序,它在 Kubernetes 中部署了 Actuator/Micrometer/Prometheus 插件

因此,非常高兴,我在对应用程序进行查询时看到了我的指标

curl http://my-service.com/prometheus
http_server_requests_seconds_count{application="my-service",exception="None",method="POST",outcome="SUCCESS",status="200",uri="/myRoute",} 1.0

并且还在位置 X 的 Prometheus 服务器中查看时间序列,查看图表。非常高兴,到目前为止一切顺利。

但是,当我想自动缩放时,什么都没有发生。

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: my-service
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: my-service
  maxReplicas: 3
  minReplicas: 1
  metrics:
  - type: Pods
    pods:
      metricName: http_server_requests_seconds_count
      targetAverageValue: "5"

请问为什么?

我的第一个想法是,我什至不确定 Kubernetes 是否知道我们的 Prometheus 服务器在 X 位置的下落。

我无法理解两者如何协同工作。

如何根据位置 X 的 Prometheus 中可用的 SpringBoot 指标(请求计数)从 Kubernetes 实现 HPA?

谢谢

4

1 回答 1

1

Kubernetes 中的自定义指标需要进一步集成才能使其正常工作。

一般来说,如果您在 prometheus 中使用自定义指标,您可以在此处使用 prometheus 适配器将 prometheus 服务器连接到 Kubernetes 中的实际自定义指标,https://github.com/DirectXMan12/k8s-prometheus-adapter

您可以通过 helm 安装它并将其连接到您的 prometheus 服务器。成功设置后,您可以从以下命令获取自定义指标,具体取决于您的 Kubernetes 版本。

kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1"

最终,当您使用 kubectl 描述 HPA 时,您将看到 HPA 对象中显示的指标。

于 2021-01-08T07:41:44.483 回答