跳到主要内容

k8s探针参数说明

· 阅读需 3 分钟
老司机
Maintainer of this proj

Kubernetes 中的探针(Probes)总结

Kubernetes 中的探针用于检测容器的健康状态和生命周期,确保容器能够正常运行并及时发现异常。主要有以下三种探针:

1. Liveness Probe(存活探针)

  • 作用:检测容器是否存活。如果探针失败,Kubernetes 会认为容器已经挂掉,并重启该容器。
  • 应用场景:容器出现死锁或无法响应时,通过重启恢复正常状态。

2. Readiness Probe(就绪探针)

  • 作用:检测容器是否准备好接收流量。如果探针失败,容器会从服务的负载均衡池中移除,不会接收请求。
  • 应用场景:容器启动完成但还未准备好处理请求时,避免流量被发送到未准备好的容器。

3. Startup Probe(启动探针)

  • 作用:检测容器的启动过程是否成功。用于启动时间较长的容器,避免因启动超时而被误判为失败。
  • 应用场景:初始化复杂、启动时间长的应用,确保启动完成后再进行存活和就绪检测。

以上探针都支持多种检测方式:

  • HTTP GET 请求
  • TCP Socket 连接
  • 执行命令(exec)

通过合理配置探针参数(如检测方式、间隔时间、超时时间、失败次数等),可以有效保障容器的稳定运行和服务的高可用性。

4. 参数列表

探针类型参数名参数类型参数支持的选项单位用途说明
LivenessProbehttpGet检测方式path, port, host, scheme, httpHeaders通过HTTP GET请求检测容器存活状态
LivenessProbetcpSocket检测方式port, host通过TCP Socket检测端口连通性
LivenessProbeexec检测方式command通过执行命令检测容器状态
LivenessProbeinitialDelaySeconds间隔时间int容器启动后等待多少秒开始第一次检测
LivenessProbeperiodSeconds间隔时间int检测间隔秒数
LivenessProbetimeoutSeconds超时时间int单次检测超时时间
LivenessProbesuccessThreshold次数int连续成功次数,默认1
LivenessProbefailureThreshold次数int连续失败次数,超过则判定失败
ReadinessProbehttpGet检测方式path, port, host, scheme, httpHeaders通过HTTP GET请求检测容器是否就绪
ReadinessProbetcpSocket检测方式port, host通过TCP Socket检测端口连通性
ReadinessProbeexec检测方式command通过执行命令检测容器是否就绪
ReadinessProbeinitialDelaySeconds间隔时间int容器启动后等待多少秒开始第一次检测
ReadinessProbeperiodSeconds间隔时间int检测间隔秒数
ReadinessProbetimeoutSeconds超时时间int单次检测超时时间
ReadinessProbesuccessThreshold次数int连续成功次数,默认1
ReadinessProbefailureThreshold次数int连续失败次数,超过则判定失败
StartupProbehttpGet检测方式path, port, host, scheme, httpHeaders通过HTTP GET请求检测容器启动状态
StartupProbetcpSocket检测方式port, host通过TCP Socket检测端口连通性
StartupProbeexec检测方式command通过执行命令检测容器启动状态
StartupProbeinitialDelaySeconds间隔时间int容器启动后等待多少秒开始第一次检测
StartupProbeperiodSeconds间隔时间int检测间隔秒数
StartupProbetimeoutSeconds超时时间int单次检测超时时间
StartupProbesuccessThreshold次数int连续成功次数,默认1
StartupProbefailureThreshold次数int连续失败次数,超过则判定失败