【k8s】livenessProbe-failureThreshold
环境
- kubernetes 1.20.4
- Spring Boot 2.5.0-M3
目标
failureThreshold 表示探针的最大失败次数,如果达到了最大的失败次数,
在存活性探针的情况,容器将重新启动。
示例
Pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: spring-k8s
spec:
containers:
- name: spring-k8s
image: jiangbo920827/spring-k8s:liveness
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: http
ports:
- name: http
containerPort: 8080
查看存活探针日志
2021-03-26 16:06:42 - GET "/actuator/health/liveness", parameters={}
2021-03-26 16:06:42 - Mapped to Actuator web endpoint 'health-path'
2021-03-26 16:06:42 - Using 'application/vnd.spring-boot.actuator.v3+json', given [*/*] and supported [application/vnd.spring-boot.actuator.v3+json, application/vnd.spring-boot.actuator.v2+json, application/json]
2021-03-26 16:06:42 - Writing [org.springframework.boot.actuate.health.CompositeHealth@731b43a6]
2021-03-26 16:06:42 - Completed 200 OK
查看存活探针
[root@master ~]# curl 10.244.1.179:8080/actuator/health/liveness|jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15 0 15 0 0 1590 0 --:--:-- --:--:-- --:--:-- 1666
{
"status": "UP"
}
停止探针
[root@master ~]# curl 10.244.1.179:8080/liveness?name=BROKEN
BROKEN[root@master ~]#
查看重启事件
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 118s default-scheduler Successfully assigned default/spring-k8s to node1
Normal Pulled 17s (x2 over 117s) kubelet Container image "jiangbo920827/spring-k8s:liveness" already present on machine
Normal Created 17s (x2 over 117s) kubelet Created container spring-k8s
Normal Started 17s (x2 over 117s) kubelet Started container spring-k8s
Warning Unhealthy 17s (x3 over 37s) kubelet Liveness probe failed: HTTP probe failed with statuscode: 503
Normal Killing 17s kubelet Container spring-k8s failed liveness probe, will be restarted
可以看到重启了,并且有三次存活探针的失败事件。
总结
通过定义 failureThreshold 来设定失败的最大次数,默认为 3 次。
附录
分类:
Kubernetes
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!