英文:
How to implement liveness/readines using springboot 2.3.0
问题
我最近了解到Spring Boot 2.3.0提供了存活性(liveness)和就绪性(readiness)功能。为了实现它们,我将Spring Boot版本更新为2.3.0,并在pom中添加了spring-boot-starter-validation依赖。我还更新了Helm图表的环境部分,包括以下内容:
name: management.health.probes.enabled
value: 'true'
name: management.endpoint.health.group.readiness.include
value: 'readinessState,db'
这些步骤是否足以实现组件的存活性和就绪性探针?如果是这样,是否有方法可以在本地测试?我的同事告诉我,如果我可以在application.properties中本地编写环境配置,那么我应该能够在本地进行测试(运行Postman并公开API,例如/actuator/health/liveness等)。
(Note: The code section remains unchanged as it is and is not translated.)
英文:
I recently learned that springboot 2.3.0 offers liveness/readiness. In order to implement them, I updated springboot version to 2.3.0 and added dependency spring-boot-starter-validation in pom. I updated helm chart's env section as well to contain:
name: management.health.probes.enabled
value: 'true'
name: management.endpoint.health.group.readiness.include
value: 'readinessState,db'
Is this all I need to in order to implement liveness and readiness probes for the component? If so, is there way to test this locally? My co-worker told me if I can write environment locally in application.properties, I should be able to test it locally (running postman and expose api such as /actuator/health/livness or something).
答案1
得分: 1
在pom中添加执行器依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
HTTP探测仅配置给在Kubernetes上运行的应用程序。您可以尝试在本地手动启用探测,使用management.health.probes.enabled=true
配置属性。
您可以通过curl或使用postman命中以下端点来检查存活性和就绪性:
-
http://localhost:8080/actuator/health/liveness
- HTTP/1.1 200 OK
{ "status": "UP", "components": { "livenessProbe": { "status": "UP" } } }
-
http://localhost:8080/actuator/health/readiness
- HTTP/1.1 503 SERVICE UNAVAILABLE
{ "status": "OUT_OF_SERVICE", "components": { "readinessProbe": { "status": "OUT_OF_SERVICE" } } }
当然,您还可以配置其他健康指标,以便检查外部系统的状态,例如数据库、Web API、共享缓存。
management.endpoint.health.group.liveness.include=livenessProbe,customCheck
英文:
Add actuator dependency in pom
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
HTTP Probes are only configured for applications running on Kubernetes. You can give it a try locally by manually enabling the probes with the management.health.probes.enabled=true
configuration property
You can check the liveness and readiness by curl or using postman to hit below endpoints
// http://localhost:8080/actuator/health/liveness
// HTTP/1.1 200 OK
{
"status": "UP",
"components": {
"livenessProbe": {
"status": "UP"
}
}
}
// http://localhost:8080/actuator/health/readiness
// HTTP/1.1 503 SERVICE UNAVAILABLE
{
"status": "OUT_OF_SERVICE",
"components": {
"readinessProbe": {
"status": "OUT_OF_SERVICE"
}
}
}
You can of course configure additional Health Indicators to be part of the Probes, checking for the state of external systems: a database, a Web API, a shared cache.
management.endpoint.health.group.liveness.include=livenessProbe,customCheck
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论