存活探针和就绪探针
【在yaml中的位置】
pod.spec.containers.readinessProbe
pod.spec.containers.livenessProbe
【三种类型】
- 命令型
livenessProbe: exec: command: - curl - 127.0.0.1:8000 initialDelaySeconds: 5 #第一次探测时等待5s periodSeconds: 5 #每5s执行一次 failureThreshold: 2 #失败的阈值 successThreshold: 1 #成功一次表示正常 timeoutSeconds: 5 # 执行检查指令的超时时间 readinessProbe: exec: #退出0 表示成功 command: - curl - 127.0.0.1:8000 initialDelaySeconds: 5 #第一次探测时等待5s periodSeconds: 5 #每5s执行一次 failureThreshold: 2 #失败的阈值 successThreshold: 1 #成功的阈值 timeoutSeconds: 3 #单次执行超时的时间
- http型
livenessProbe: httpGet: path: / port: 8000 scheme: HTTP # 返回200表示正常 initialDelaySeconds: 5 #第一次探测时等待5s periodSeconds: 5 #每5s执行一次 failureThreshold: 2 #失败的阈值 successThreshold: 1 #成功的阈值 timeoutSeconds: 3 #单次执行超时的时间 readinessProbe: httpGet: path: / port: 8000 scheme: HTTP initialDelaySeconds: 5 #第一次探测时等待5s periodSeconds: 5 #每5s执行一次 failureThreshold: 2 #失败的阈值 successThreshold: 1 #成功的阈值 timeoutSeconds: 3 #单次执行超时的时间
- tcp型
livenessProbe: tcpSocket: port: 8000 initialDelaySeconds: 5 #第一次探测时等待5s periodSeconds: 5 #每5s执行一次 failureThreshold: 2 #失败的阈值 successThreshold: 1 #成功的阈值 timeoutSeconds: 3 #单次执行超时的时间 readinessProbe: tcpSocket: port: 8000 initialDelaySeconds: 5 #第一次探测时等待5s periodSeconds: 5 #每5s执行一次 failureThreshold: 2 #失败的阈值 successThreshold: 1 #成功的阈值 timeoutSeconds: 3 #单次执行超时的时间
【事例】
apiVersion: extensions/v1beta1 # 指定Deployment的版本 通过kubectl explain Deployment查看 kind: Deployment metadata: name: test-label # Deployment的名字 spec: replicas: 3 # pod副本数 selector: matchLabels: app: web # 选择 带有app=web的pod进行管理 template: # 生成 pod 的模板 metadata: labels: app: web # 给pod贴的标签 spec: containers: - name: web image: python imagePullPolicy: IfNotPresent # image拉取的策略 Never Always ports: # container 运行的端口 - containerPort: 8000 args: - "python" - "-m" - "http.server" livenessProbe: httpGet: path: / port: 8000 scheme: HTTP initialDelaySeconds: 5 #第一次探测时等待5s periodSeconds: 5 #每5s执行一次 failureThreshold: 2 #失败的阈值 successThreshold: 1 #成功的阈值 timeoutSeconds: 3 #单次执行超时的时间 readinessProbe: httpGet: path: / port: 8000 scheme: HTTP initialDelaySeconds: 5 #第一次探测时等待5s periodSeconds: 5 #每5s执行一次 failureThreshold: 2 #失败的阈值 successThreshold: 1 #成功的阈值 timeoutSeconds: 3 #单次执行超时的时间
分类:
k8s
标签:
livenessProbe
, readinessProbe
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏