基于spring-boot-starter-actuator不同版本(2.1.3和2.3.5)在K8s中做就绪存活检查相关配置的差异
springboot2.1和springboot2.3的应用,在k8s中的就绪存活检查相关配置的差异
今天遇到一个问题,K8s的Deployment在对某服务的POD进行健康检查的时候,由于直接copy了之前服务的相关配置导致就绪检查一直过不去,因而造成服务对应POD的READY状态一直处于0/1(期望是1/1)。
经排查发现,原因是两个服务的spring-boot-starter-actuator的版本不同,对就绪存活检查的配置不兼容导致的。
首先,我们之前的服务依赖的是spring-boot-starter-actuator.2.1.3.RELEASE,与该服务对应的Deployment的YAML文件中关于就绪存活探针的配置如下:
readinessProbe:
httpGet:
path: /actuator/health
port: 20000
initialDelaySeconds: 30
timeoutSeconds: 10
livenessProbe:
httpGet:
path: /actuator/health
port: 20000
initialDelaySeconds: 60
timeoutSeconds: 10
这里我们可以看到,就绪和存活探针都是基于 spring-boot-starter-actuator 的 /actuator/health 端点。
下面,再来说下我们新的服务:
新的服务依赖的是spring-boot-starter-actuator.2.3.5.RELEASE,起初也是采用了上边的Deployment的YAML文件中关于就绪存活探针配置。
如此配置的结果正如本文开头介绍的那样,POD的一直处于无法就绪状态。
通过官方文档我们发现,在Spring Boot 2.3中引入了容器探针,也就是spring-boot-starter-actuator增加了 /actuator/health/readiness 和 /actuator/health/liveness 两个endpoint,分别用于就绪和存活检查。
所以,基于spring-boot-starter-actuator.2.3.5.RELEASE做就绪存活检查的配置应该如下:
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: 20000
initialDelaySeconds: 30
timeoutSeconds: 10
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 20000
initialDelaySeconds: 60
timeoutSeconds: 10
最后,总结以下两点:
- 依赖 spring-boot-starter-actuator.2.1.3.RELEASE 的项目,就绪和存活探针可采用端点 /actuator/health
- 依赖 spring-boot-starter-actuator.2.3.5.RELEASE 的项目,就绪探针采用端点 /actuator/health/readiness,存活探针采用端点 /actuator/health/liveness
更多推荐
所有评论(0)