Я начинаю с Kubernetes и пытаюсь узнать больше о тесте живучести.
В некоторых документах и статьях указано, что значение по умолчанию failureThreshold
составляет 3 раза. И если вы не укажете failThreshold, 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?
После создания модуля:
$ 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