Java SpringBoot Kubernetes:水平pod自动缩放



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

我有一个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的普罗米修斯服务器中看到时间序列,看到图表。很开心,到目前为止还不错。

但是,当我想要自动缩放时,什么都不会发生。

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是否知道我们普罗米修斯服务器在X位置的位置。

我很难理解两者是如何协同工作的。

如何根据Prometheus中X位置的SpringBoot度量(请求计数(从Kubernetes实现HPA?

谢谢

Kubernetes中的自定义度量需要进一步的集成才能发挥作用。

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

您可以通过helm安装它,并将其连接到您的prometheus服务器。一旦您成功地设置了它,您就可以根据您的Kubernetes版本从以下命令中获得自定义度量。

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

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

最新更新