如何使用 Spring Actuator 配置 Kubernetes 启动探针

问题描述

我已经阅读了一些文档并弄清楚了如何使用 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 不会为启动探针公开单独的端点。您也可以在此用例中使用活性探针。 在 kubernetes 中使用不同探针的原因是为应用程序的初始启动启用长时间超时,这可能需要一些时间。在第一次成功启动探测器调用后,活性探测器接管,减少超时值以快速检测故障并重新启动应用程序。