【问题标题】:Spring Boot Actuator Kubernetes Probes returning 404Spring Boot Actuator Kubernetes Probes 返回 404
【发布时间】:2020-10-28 05:58:25
【问题描述】:

我正在尝试使用 Spring Boot Actuator 中的 Kubernetes Probes,但它不起作用。

我在 application.properties 中设置了以下内容:

management.endpoints.web.path-mapping.health=probes
management.endpoint.health.group.ping.include=ping
management.endpoint.health.group.liveness.include=livenessState
management.endpoint.health.group.readiness.include=readinessState

组按预期列出:

$ curl http://localhost:8080/actuator/probes
{"status":"UP","groups":["liveness","ping","readiness"]}

ping 按预期工作:

$ curl http://localhost:8080/actuator/probes/ping
{"status":"UP"}

但是livenessreadiness 都返回Status Code: 404Content-Length: 0


我正在使用spring-boot-starter-parent 版本2.3.1.RELEASE

我想要的探测记录在Auto-configured HealthIndicators的列表中。

该功能也描述在:https://spring.io/blog/2020/03/25/liveness-and-readiness-probes-with-spring-boot

我尝试了几种livenessState 的拼写,包括livenessProbe(在博文中),但没有任何效果。

这是一个相关的答案,但它并没有直接解决我的问题:Kubernetes - Liveness and Readiness probe implementation

我缺少什么配置?


更新

链接网站中存在一些暗示潜在线索的措辞...

如果部署在 Kubernetes 环境中,执行器将收集“Liveness”和“Readiness”信息...

也许这表明探针只有在部署在 Kubernetes 环境中才能工作——尽管我不知道如何检测到这种情况或为什么会出现这种情况。

【问题讨论】:

标签: spring-boot-actuator


【解决方案1】:

使用include=livenessStateinclude=readinessState 是正确的。示例here(显示include=livenessProbe)是错误的。

我通过反复试验确定了正确的名称 - 在 Kubernetes 环境中运行时检查结果

management.endpoint.health.group.exploratory.include=livenessState,readinessState,ping
management.endpoint.health.group.exploratory.show-details=always

神奇地,并且没有明显的原因,当您执行标准本地运行时,这些指标不可用 - 您会收到 404 用于没有可用包含的健康组。

供参考:

【讨论】:

  • 我认为在本地运行时指标不显示的原因是您只能看到相关健康指标的更广泛功能的一部分。例如,除非您尝试连接到 Redis 主机,否则它不会告诉您“redis”状态。
  • 跟随另一条评论中的链接,我发现 2.3.2 中引入了一个重大更改:github.com/spring-projects/spring-boot/issues/…
【解决方案2】:

添加以下配置对我有用(通过反复试验)

management.health.livenessstate.enabled=true
management.health.readinessstate.enabled=true

如果你在本地运行,还需要添加

management.endpoint.health.probes.enabled=true

我正在使用spring-boot-starter-parent 版本2.3.2.RELEASE

【讨论】:

猜你喜欢
  • 2019-09-16
  • 2020-02-18
  • 2016-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-08
  • 1970-01-01
  • 2020-10-07
相关资源
最近更新 更多