云容器实例 CCI-存活探针(liveness probe):Exec

时间:2023-12-21 21:07:00

Exec

Exec即执行具体命令,具体机制是probe执行容器中的命令并检查命令退出的状态码,如果状态码为0则说明健康,定义方法如下所示。

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; sleep 600
    livenessProbe:           # liveness probe
      exec:                  # Exec定义
        command:
        - cat
        - /tmp/healthy

上面定义在容器中执行cat /tmp/healthy命令,如果成功执行并返回0,则说明容器是健康的。

support.huaweicloud.com/devg-cci/cci_05_0013.html