livenessProbe: 是指容器是否正在运行。如果存活性探测失败,则kubelete会杀死容器,并且容器受重启策略的影响。如果容器不提供存活性探针,则默认状态为Success。

[root@k8s-master01 k8s-test]# cat liveness.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: liveness-exec-pod
  namespace: default
spec:
  containers:
  - name: liveness-exec-container
    image: kone.com/library/busybox
    imagePullPolicy: IfNotPresent
    command: ["/bin/sh", "-c", "touch /tmp/live-test; sleep 60; rm -f /tmp/live-test; sleep 3600"]
    livenessProbe:
      exec:
        command: ["test", "-e", "/tmp/live-test"]
      initialDelaySeconds: 1
      periodSeconds: 3
[root@k8s-master01 k8s-test]# 

kubectl create -f liveness.yaml创建容器后
kubectl get pod -w查看容器liveness-exec-pod在不断的重启


[root@k8s-master01 k8s-test]# kubectl get pod -w
NAME                               READY   STATUS    RESTARTS   AGE
liveness-exec-pod                  1/1     Running   1          2m51s
liveness-exec-pod                  1/1     Running   2          3m20s
liveness-exec-pod                  1/1     Running   3          4m59s
liveness-exec-pod                  1/1     Running   4          6m38s
liveness-exec-pod                  1/1     Running   5          8m17s
liveness-exec-pod                  1/1     Running   6          9m56s
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐