OpenShift aPaaS v3 失败的 Liveness 探测与失败的 Readiness 探测
OpenShift aPaaS v3 failed Liveness probes vs failed Readiness Probes
如果 pod Liveness 探测池中的一个池和 pod Readiness 探测池中的一个失败,会发生什么情况?
活性探测和就绪探测之间几乎没有什么区别。但主要区别之一是准备就绪探测失败会从池中删除 pod,但不要重新启动。另一方面,失败的 liveness 探测会从池中删除 pod 并重新启动 pod。
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness-vs-readiness
name: liveness-vs-readiness-exec
spec:
containers:
- name: liveness
image: k8s.gcr.io/busybox
args:
- /bin/sh
- -c
- touch /tmp/healthy; touch /tmp/liveness; sleep 999999
livenessProbe:
exec:
command:
- cat
- /tmp/liveness
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
让我们创建这个 pod 并展示它的实际效果:oc create -f liveness-vs-readiness.yaml
当我们在 pod 中执行操作时输出 pod 状态。名字前面的数字对应pod内完成的动作:
oc get pods -w
NAME READY STATUS RESTARTS AGE
[1] liveness-vs-readiness-exec 1/1 Running 0 44s
[2] liveness-vs-readiness-exec 0/1 Running 0 1m
[3] liveness-vs-readiness-exec 1/1 Running 0 2m
[4] liveness-vs-readiness-exec 0/1 Running 1 3m
liveness-vs-readiness-exec 1/1 Running 1 3m
容器内的操作:
[root@default ~]# oc rsh liveness-vs-readiness-exec
# [1] we rsh to the pod and do nothing. Pod is healthy and live
# [2] we remove health probe file and see that pod goes to notReady state
# rm /tmp/healthy
#
# [3] we create health file. Pod goes into ready state without restart
# touch /tmp/healthy
#
# [4] we remove liveness file. Pod goes into notready state and is restarted just after that
# rm /tmp/liveness
# command terminated with exit code 137
如果 pod Liveness 探测池中的一个池和 pod Readiness 探测池中的一个失败,会发生什么情况?
活性探测和就绪探测之间几乎没有什么区别。但主要区别之一是准备就绪探测失败会从池中删除 pod,但不要重新启动。另一方面,失败的 liveness 探测会从池中删除 pod 并重新启动 pod。
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness-vs-readiness
name: liveness-vs-readiness-exec
spec:
containers:
- name: liveness
image: k8s.gcr.io/busybox
args:
- /bin/sh
- -c
- touch /tmp/healthy; touch /tmp/liveness; sleep 999999
livenessProbe:
exec:
command:
- cat
- /tmp/liveness
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
让我们创建这个 pod 并展示它的实际效果:oc create -f liveness-vs-readiness.yaml
当我们在 pod 中执行操作时输出 pod 状态。名字前面的数字对应pod内完成的动作:
oc get pods -w
NAME READY STATUS RESTARTS AGE
[1] liveness-vs-readiness-exec 1/1 Running 0 44s
[2] liveness-vs-readiness-exec 0/1 Running 0 1m
[3] liveness-vs-readiness-exec 1/1 Running 0 2m
[4] liveness-vs-readiness-exec 0/1 Running 1 3m
liveness-vs-readiness-exec 1/1 Running 1 3m
容器内的操作:
[root@default ~]# oc rsh liveness-vs-readiness-exec
# [1] we rsh to the pod and do nothing. Pod is healthy and live
# [2] we remove health probe file and see that pod goes to notReady state
# rm /tmp/healthy
#
# [3] we create health file. Pod goes into ready state without restart
# touch /tmp/healthy
#
# [4] we remove liveness file. Pod goes into notready state and is restarted just after that
# rm /tmp/liveness
# command terminated with exit code 137