• 基于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
  • 相关阅读:
    spring中有哪几种加载ApplicationContext.xml的方式呢?
    (附源码)计算机毕业设计SSM洁强汽车美容
    ubuntu系统Anaconda下载安装教程
    【English】十大词性之介词
    图文并茂 —— 插入排序,希尔排序
    力扣第455题 分发饼干 c++ 贪心 经典题
    【Java 进阶篇】MySQL多表查询之外连接详解
    技术对接48
    Xinlinx zynq7010国产替代 FMQL10S400 全国产化 ARM 核心板+扩展板
    【== 和 equals 的区别是什么?】
  • 原文地址:https://blog.csdn.net/yangchao1125/article/details/134421299