k8s-----7、Pod健康检查

健康检查

1、健康检查

  • 健康检查可以分为两种

  • 1、livenessProbe (存活检查)。如果检查失败,将杀死容器,通过Pod的restartPolicy来操作。

  • 2、readinessProbe(就绪检查)。如果检查失败,k8s会将Pod从Service endpoints中剔除。

  • Probe支持的三种检查方式:

  • 1、httpGet,发送HTTP请求,如果返回200-400的状态码,为成功。

  • 2、exec,执行shell命令返回的状态码为0表示成功

  • 3、tcpSocket,发起tcp Socket建立成功

bash 复制代码
# 通过exec进行演示状态码的变化
[root@master example]# vim healthy.yaml
[root@master example]# touch /tmp/healthy
[root@master example]# echo $?
0
[root@master example]# rm -fr /tmp/healthy 
[root@master example]# cat /tmp/healthy
cat: /tmp/healthy: No such file or directory
[root@master example]# echo $?
1

# 通过yaml文件进行展示
[root@master example]# cat healthy.yaml 
apiVersion: v1
kind: Pod
metadata: 
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: busybox
    args:
    - /bin/sh
    - -c 
    - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy
    livenessProbe:    #健康检测部分代码
      exec:
        command:
        - cat 
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5
相关推荐
蝎子莱莱爱打怪11 小时前
GitLab CI/CD + Docker Registry + K8s 部署完整实战指南
后端·docker·kubernetes
阿里云云原生4 天前
阿里云获评 Agentic AI 开发平台领导者,函数计算 AgentRun 赢下关键分!
云原生
蝎子莱莱爱打怪4 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
阿里云云原生4 天前
MSE Nacos Prompt 管理:让 AI Agent 的核心配置真正可治理
微服务·云原生
阿里云云原生4 天前
当 AI Agent 接管手机:移动端如何进行观测
云原生·agent
阿里云云原生4 天前
AI 原生应用开源开发者沙龙·深圳站精彩回顾 & PPT下载
云原生
阿里云云原生4 天前
灵感启发:日产文章 100 篇,打造“实时热点洞察”引擎
云原生
~莫子4 天前
Haproxy七层负载详解+实验详细代码
云原生
阿里云云原生4 天前
OpenTelemetry + 云监控 2.0:打造你的云原生全栈可观测
云原生
阿里云云原生5 天前
Kubernetes 官方再出公告,强调立即迁移 Ingress NGINX
kubernetes