【k8s】livenessProbe-exec
环境
- kubernetes 1.20.4
- Spring Boot 2.5.0-M3
目标
livenessProbe 是一个存活性探针,可以通过多种方式定义存活性探针。
下面通过 exec 的方式定义一个存活性探针,并且让其失败。
示例
Pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: busybox
spec:
containers:
- name: busybox
image: busybox:stable
livenessProbe:
exec:
command: ["cat", "/tmp/healthy"]
command:
[
"/bin/sh",
"-c",
"touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600",
]
定义了一个启动命令,首先在 /tmp 目录下新建了一个文件,睡眠 30 秒后又进行了删除。
看到的现象是容器首先启动成功了,在等待 30 秒后,开始发现存活性探针失败,连续检测三次失败后,重启容器。
查看
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 64s default-scheduler Successfully assigned default/busybox to node2
Normal Pulled 64s kubelet Container image "busybox:stable" already present on machine
Normal Created 63s kubelet Created container busybox
Normal Started 63s kubelet Started container busybox
Warning Unhealthy 6s (x3 over 26s) kubelet Liveness probe failed: cat: can't open '/tmp/healthy': No such file or directory
Normal Killing 6s kubelet Container busybox failed liveness probe, will be restarted
总结
通过执行命令的方式,来实现了一个存活性探针,在检测到探针失败时,容器进行了重启。
附录
分类:
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框架的用法!