• 基于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
  • 相关阅读:
    目标文件(ELF格式)
    NIO和多路复用
    React小项目-在线计算器(下)
    海量数据去重的Hash与BloomFilter学习笔记
    数据库 高阶语句
    干货 | 基于深度学习的生态保护红线和生态空间管控区域内开发建设活动识别...
    【MATLAB源码-第52期】基于matlab的4用户DS-CDMA误码率仿真,对比不同信道以及不同扩频码。
    dos2unix和unix2dos
    【Java面试】为什么重写equals方法必须同时重写HashCode方法?
    Nacos极简教程
  • 原文地址:https://blog.csdn.net/yangchao1125/article/details/134421299