• 基于spring-boot-starter-actuator不同版本(2.1.3和2.3.5)在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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    这里我们可以看到,就绪和存活探针都是基于 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    最后,总结以下两点:

    1. 依赖 spring-boot-starter-actuator.2.1.3.RELEASE 的项目,就绪和存活探针可采用端点 /actuator/health
    2. 依赖 spring-boot-starter-actuator.2.3.5.RELEASE 的项目,就绪探针采用端点 /actuator/health/readiness,存活探针采用端点 /actuator/health/liveness
  • 相关阅读:
    SAP角色描述-只能在Logon语言中修改问题解决 .
    APP广告变现策略:如何实现盈利与用户体验的平衡?
    Day21:算法篇之动态规划dp
    Java的两大、三类代理模式
    褶积合成地震记录
    Windows保护模式(七)2-9-9-12分页
    【深度学习】实验13 使用Dropout抑制过拟合
    前端周刊第三十期
    万字总结线程池
    带你掌握如何查看并读懂昇腾平台的应用日志
  • 原文地址:https://blog.csdn.net/yangchao1125/article/details/134421299