【问题标题】:How to configure Kubernetes startup probe with Spring Actuator如何使用 Spring Actuator 配置 Kubernetes 启动探针
【发布时间】:2021-06-16 17:30:22
【问题描述】:

我已经阅读了一些文档,并了解了如何使用 Actuator 设置就绪和活跃端点,例如 this 之一。但我无法弄清楚如何为“启动”探测设置端点。

我的应用程序 yml:

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: "ALWAYS"
      group:
        readiness.include: readinessProbe, dataStream
        startup.include: readinessProbe, dataStream

我的部署配置:

  livenessProbe:
    httpGet:
      path: "/actuator/health/liveness"
      port: "http"
    initialDelaySeconds: 600
    periodSeconds: 15
  readinessProbe:
    httpGet:
      path: "/actuator/health/readiness"
      port: "http"
    periodSeconds: 30
    failureThreshold: 15
  startupProbe:
    httpGet:
      path: "/actuator/health/startup"
      port: "http"
    initialDelaySeconds: 150
    periodSeconds: 10
    failureThreshold: 30

执行器似乎没有提供“启动”探测的 URL,或者换句话说,http://localhost:8080/actuator/health/startup 不起作用。如何设置?

【问题讨论】:

  • 错误信息是什么?您使用的是哪个 Spring Boot 版本?
  • @Thomas 错误信息是404,spring-boot版本是2.4.4
  • 你的 server.servlet.contextPath 是什么?

标签: spring-boot kubernetes startup spring-boot-actuator readinessprobe


【解决方案1】:

Spring boot 不会为启动探测公开单独的端点。您也可以将 liveness probe 用于此用例。 在 kubernetes 中使用不同探针的原因是为应用程序的初始启动启用长时间超时,这可能需要一些时间。在第一次成功的启动探测调用后,活性探测接管,减少超时值以快速检测故障并重新启动应用程序。

【讨论】:

  • 我正在考虑将其映射到就绪探针而不是活性。我的应用程序需要一些时间来加载大量配置。因此,在加载时,我触发了 LivenessState.CORRECT 和 ReadinessState.REFUSING_TRAFFIC 事件,当加载完成时,我最终触发了 ReadinessState.ACCEPTING_TRAFFIC。因此,只有在所有配置准备就绪时,应用才会报告正在接受请求。
  • 我看不出有什么情况可以改善。在我看来,启动探针为应用程序启动期间的活性探针提供了不同的配置,以防止容器过早重启。即使运行它也不会收到流量,直到 readinessprobe 发出信号表明它没问题。
  • 加载时间有点不可预测,所以在 Kubernetes 中使用时,我想避免长期存在的 BROKEN 状态可能触发不必要的 Pod 重启。另一方面,如果问题是真实的并且我们处于 BROKEN 状态,我不想延长 Kubernbetes 在尝试重新启动之前等待的时间。
  • 这就是为什么您可以为启动探测使用较短的轮询间隔和较长的超时时间,然后您可以为活性探测使用较短的超时时间和较长的时间间隔。
猜你喜欢
  • 2023-02-16
  • 2021-12-03
  • 2020-04-11
  • 2023-03-17
  • 2019-05-29
  • 2018-02-28
  • 2019-07-22
  • 2018-08-16
  • 2019-05-06
相关资源
最近更新 更多