我正在开始使用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发布于 2020-04-12 13:01:47
这取决于PodSpec中的restartPolicy。
PodSpec有一个restartPolicy字段,可能的值有Always、OnFailure和Never。默认值为Always。restartPolicy适用于实例中的所有容器。restartPolicy仅指容器在同一节点上被kubelet重启。kubelet重启的已退出容器会以指数延迟(10s、20s、40s…)重新启动上限为5分钟,并在成功执行10分钟后重置
发布于 2020-04-26 22:58:28
感谢您的回复。我看到过一些类似的答案,但这并不能很好地解释一个pod会重启多少次。答案是,从今天起,它将永远以“总是”的默认模式重新启动。
似乎没有办法设置最大重启次数。
您可以重启" always“、"on failure”或"never“。在always和on failure模式下,5分钟是重试启动容器的最大等待时间。
"Never“不会重新启动容器。
因此,目前还没有帮助我们设置最大重试次数的选项。
引用Dan Wahlin的话,他有一门关于这个主题的课程:
首先,5分钟数字是两次重新启动之间的最大上限时间。如果你再次运行它,你会看到它肯定会开始减慢重新启动的速度(见下文),并且会达到每5分钟才尝试一次的程度。它坚持使用这个数字,除非容器是健康的(在这种情况下,它会重置一些东西)。
至于重启的最大次数(这就是你的问题,我现在意识到了),从我在github网站上可以看出,他们似乎还在研究这个功能。我通常不需要处理这种情况(通常是集群管理员),但如果我遇到任何其他情况,我会让您知道的。
https://github.com/kubernetes/kubernetes/issues/49466 https://github.com/kubernetes/kubernetes/pull/79334
看起来这是一个特定的拉取请求来解决这个问题:
https://stackoverflow.com/questions/61160757
复制相似问题