【k8s】livenessProbe-periodSeconds
环境
- kubernetes 1.20.4
- Spring Boot 2.5.0-M3
目标
periodSeconds 表示探针的探测周期,默认情况下是 10 秒。
下面演示将周期修改成 5 秒。
示例
Pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: spring-k8s
spec:
containers:
- name: spring-k8s
image: jiangbo920827/spring-k8s:trace
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: http
periodSeconds: 5
ports:
- name: http
containerPort: 8080
查看
2021-03-25 16:17:56.209 TRACE 1 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerAdapter : Applying default cacheSeconds=-1
2021-03-25 16:17:56.210 TRACE 1 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : No view rendering, null ModelAndView returned.
2021-03-25 16:17:56.210 DEBUG 1 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed 200 OK, headers={masked}
2021-03-25 16:18:01.199 TRACE 1 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : GET "/actuator/health/liveness", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
2021-03-25 16:18:01.199 TRACE 1 --- [nio-8080-exec-5] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped to Actuator web endpoint 'health-path'
2021-03-25 16:18:01.200 TRACE 1 --- [nio-8080-exec-5] o.s.web.method.HandlerMethod : Arguments: [org.apache.catalina.connector.RequestFacade@29d96d2f, null]
2021-03-25 16:18:01.200 DEBUG 1 --- [nio-8080-exec-5] o.s.w.s.m.m.a.HttpEntityMethodProcessor : 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-25 16:18:01.200 TRACE 1 --- [nio-8080-exec-5] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [org.springframework.boot.actuate.health.CompositeHealth@7294e8dd]
2021-03-25 16:18:01.208 TRACE 1 --- [nio-8080-exec-5] s.w.s.m.m.a.RequestMappingHandlerAdapter : Applying default cacheSeconds=-1
2021-03-25 16:18:01.209 TRACE 1 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : No view rendering, null ModelAndView returned.
2021-03-25 16:18:01.209 DEBUG 1 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : Completed 200 OK, headers={masked}
可以看到每过 5 秒,就收到了存活探针的请求。
总结
通过定义 periodSeconds 来设置探针的探测间隔。
【推荐】国内首个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框架的用法!