spring-boot - Spring Boot 自定义 Kubernetes 就绪探针
问题描述
我想实现自定义逻辑来确定我的 pod 的准备情况,我检查了这个:https ://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints.kubernetes -probes.external-state并且他们提到了一个示例属性:
management.endpoint.health.group.readiness.include=readinessState,customCheck
问题是 - 我如何覆盖customCheck
?在我的情况下,我想使用 HTTP 探针,所以 yaml 看起来像:
readinessProbe:
initialDelaySeconds: 10
periodSeconds: 10
httpGet:
path: /actuator/health
port: 12345
话又说回来-我应该在哪里以及如何应用确定应用程序何时准备就绪的逻辑(就像上面的链接一样,我想依靠外部服务才能准备好)
解决方案
customCheck 是自定义 HealthIndicator 的键。给定 HealthIndicator 的键是不带 HealthIndicator 后缀的 bean 的名称
您正在定义 readinessProbe,因此可能点击 /actuator/health/readiness 是更好的选择。
public class CustomCheckHealthIndicator extends AvailabilityStateHealthIndicator {
private final YourService yourService;
public CustomCheckHealthIndicator(ApplicationAvailability availability, YourService yourService) {
super(availability, ReadinessState.class, (statusMappings) -> {
statusMappings.add(ReadinessState.ACCEPTING_TRAFFIC, Status.UP);
statusMappings.add(ReadinessState.REFUSING_TRAFFIC, Status.OUT_OF_SERVICE);
});
this.yourService = yourService;
}
@Override
protected AvailabilityState getState(ApplicationAvailability applicationAvailability) {
if (yourService.isInitCompleted()) {
return ReadinessState.ACCEPTING_TRAFFIC;
} else {
return ReadinessState.REFUSING_TRAFFIC;
}
}
}
推荐阅读
- c++ - 声明一个变量,该变量具有 c++ 或 c 中的值,在程序终止时不会被销毁
- latex - 如何制作自定义的 LaTeX 符号
- macos - 将 PCL 升级到 .NET Standard 2.0 后在 Mac 上构建错误
- r - R中的标准偏差
- angular - Visual Studio 代码,tslint 显示未检查的暂存更改
- python - Python 解析名为“class”的 csv 元素(Python 关键字)
- ubuntu - Ubuntu获取MAC地址所有设备也不在网络中
- python - 从 Python 2.7 迁移到 3.8:“TypeError:需要类似字节的对象,而不是 'str'”
- c# - 动态反序列化 JSON 以访问其泛型类型
- python - 为什么我在 python 中没有得到 chromedriver 异常