Deployment会创建一个ReplicaSet , ReplicaSet会维护你的Pod
Liveness 和 Readiness 探针是在容器级别配置的,当 Pod 的所有容器都准备好时,就认为 Pod 准备好了。
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-exec
spec:
containers:
- name: liveness
image: k8s.gcr.io/busybox
args:
- /bin/sh
- -c
- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
Spring 执行器健康检查 API 是捆绑在容器中的应用程序的一部分。
Kubernetes 会检查 Pod 中每个容器的 liveness 和 readiness 探针,如果这些探针中的任何一个在一定时间后未能成功返回并尝试,它将杀死该 pod 并启动一个新的。
在部署级别设置探测没有意义,因为您可能有多个 Pod 在同一部署下运行,并且如果您的一个 Pod 不健康,您不希望杀死健康的 Pod。
使用相同 pod 配置的部署描述符将是这样的:
apiVersion: apps/v1
kind: Deployment
metadata:
name: liveness-deployment
labels:
app: liveness
spec:
replicas: 3
selector:
matchLabels:
app: liveness
template:
metadata:
labels:
app: liveness
spec:
containers:
- name: liveness
image: k8s.gcr.io/busybox
args:
- /bin/sh
- -c
- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5