实现容器探测的几种方式: 探针类型有三种: ExecAtion TCPSocketAction HTTPGetAction
那么探针针对于存活性来做的话,就是存活性探针,针对就绪来做,就是就绪性探针
那么 livenessProbe 是做存活性探测 ,存活未必就绪
livenessProbe <Object>
Periodic probe of container liveness. Container will be restarted if the
probe fails. Cannot be updated. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
readinessProbe 是做就绪性探测的
readinessProbe <Object>
Periodic probe of container service readiness. Container will be removed
from service endpoints if the probe fails. Cannot be updated. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
lifecycle <Object>
Actions that the management system should take in response to container
lifecycle events. Cannot be updated.
[root@server1 ~]# kubectl explain pods.spec.containers.livenessProbe
下面是三种定义的探针,那么我们每次定义的时候都定义三种中的一种就可以了
exec <Object>
One and only one of the following should be specified. Exec specifies the
action to take.
httpGet <Object>
HTTPGet specifies the http request to perform.
tcpSocket <Object>
TCPSocket specifies an action involving a TCP port. TCP hooks not yet
supported
这个字段的意思是,探针在探测的过程中,并不是一开始探测的时候,探测到失败就认为是失败的,那么只有探测3次以上才认为它是失败的。
failureThreshold <integer>
Minimum consecutive failures for the probe to be considered failed after
having succeeded. Defaults to 3. Minimum value is 1.
这个字段表示探测的生命周期,也就是间隔多长时间进行探测一次 ,默认是10秒探测一次
periodSeconds <integer>
How often (in seconds) to perform the probe. Default to 10 seconds. Minimum
value is 1.
那么在探测的时候始终没有响应应该等多久,默认是等待的1秒钟
timeoutSeconds <integer>
Number of seconds after which the probe times out. Defaults to 1 second.
Minimum value is 1. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
因为容器在启动的时候是需要进行初始化的,因此在初始化期间是不能被探测的,那么在初始化的这个时间段,我们延迟探测的时间,因此我们要定义这个时间段在容器初始化完成后进行探测,那么如果不定义的话,那么默认的情况下是容器一启动就会进行探测,那么容器启动并不代表主进程可以对外服务了
initialDelaySeconds <integer>
Number of seconds after the container has started before liveness probes
are initiated. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
那么下来写一个探测性的pod对象的用于检测的exec探针的pod对象
[root@server1 ~]# vim liveness-exec.yaml
apiVersion: v1
kind: Pod
metadata:
name: liveness-exec-pod
namespace: default
spec:
containers:
- name: liveness-exec-container
image: busybox:latest
imagePullPolicy: IfNotPresent 镜像的拉取策略,如果不再则拉取,在再则不拉取
command: ["bin/sh","-c","touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 3600"] 在容器内部执行的命令
livenessProbe: 做存活性探测
exec: 使用exec的探针
command: ["test","-e","/tmp/healthy"] exec 默认使用命令做探针 -e 检测创建的文件是否存在
initialDela