【笔记】Kubernetes存活探针

前言

Kubernetes存活探针学习笔记
在部署文件中,我们添加探针,来探测容器的健康状态
探针默认每10秒探测一次,连续三次探测失败后重启容器

存活探针的类型

HTTP GET

  • 返回2xx或3xx响应码则认为探测成功

TCP

  • 与指定端口建立TCP连接,连接成功则为探测成功

Exec

  • 在容器内执行指定的任意命令,并检查命令的退出码,退出码为0则为探测成功

修改配置文件

  • 修改pod配置文件

spec.containers.livenessProbe:存活探针配置
spec.containers.livenessProbe.httpGet:存活探针类型为HttpGet
spec.containers.livenessProbe.httpGet.path:探测路径
spec.containers.livenessProbe.httpGet.port:探测端口
spec.containers.livenessProbe.initialDelaySeconds:第一次探测的延迟时间

1
2
3
4
5
6
7
spec:
containers:
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 15

探针的描述

1
kubectl describe po <name>

Liveness:存货探针的参数

http-get:探测类型
http://:8080/:探测路径
delay:第一次探测间隔
timeout:超时时间
period:探测间隔
success:探测成功次数
failure:探测失败次数

完成