【发布时间】:2020-07-24 09:51:09
【问题描述】:
我正在开始使用 Kubernetes,我正在尝试了解有关活性探测的更多信息。
一些文档和文章告诉failureThreshold 的默认值是 3 倍。而当你不指定 failureThreshold 时,Kubernetes 会在重启容器之前进行 3 次探测。
我的问题是,kubelet 重启 pod 容器多少次?
这是一个示例 livenessprobe-execaction.yaml:
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-exec
spec:
containers:
- name: liveness
image: k8s.gcr.io/busybox
args: # command to be executed when the container starts
- /bin/sh
- -c
- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600 # during first 30 seconds there will be a file and cat will return success, when removed, a failure
livenessProbe:
exec:
command: # in the first probe there will be a file within 30 seconds, and no errors
# and after 35 seconds a nex probe is done but the file is gone, and error will show up and machine will be restarted
# several restarts should happen or restarts only 3 times?
- cat
- /tmp/healthy
initialDelaySeconds: 5 # kubelet waits 5 seconds before first probe
periodSeconds: 5 # kubelet checks every 5 seconds
#failureThreshold: 3 is the default number of times, after the 3rd liveness probe the container is restarted? forever?
创建 pod 后:
$ kubectl apply -f livenessprobe-execaction.yaml
还有手表:
$ kubectl get pod liveness-exec --watch
输出是:
NAME READY STATUS RESTARTS AGE
liveness-exec 1/1 Running 0 4s
liveness-exec 1/1 Running 1 75s
liveness-exec 1/1 Running 2 2m29s
liveness-exec 1/1 Running 3 3m44s
liveness-exec 1/1 Running 4 5m
liveness-exec 1/1 Running 5 6m14s
liveness-exec 0/1 CrashLoopBackOff 5 7m29s
liveness-exec 1/1 Running 6 8m57s
liveness-exec 1/1 Running 7 10m
liveness-exec 0/1 CrashLoopBackOff 7 11m
liveness-exec 1/1 Running 8 16m
liveness-exec 1/1 Running 9 17m
liveness-exec 0/1 CrashLoopBackOff 9 18m
【问题讨论】:
标签: kubernetes