liveness Probe 容器存活状态检测,控制是否重启

readiness Probe 容器就绪状态检测,控制容器是否就绪

可以通过如下命令分别获取支持参数

1
2
kubectl explain pods.spec.containers.livenessProbe
kubectl explain pods.spec.containers.readinessPorbe
探针类型分为三种
- exec
- httpGet
- tcpSocket
liveness-exec.yaml 容器存活 exec 示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
apiVersion: v1
kind: Pod
metadata:
name: liveness-exec-pod
namespace: default
spec:
containers:
- name: liveness-exec-container
image: busybox:latest
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","touch /tmp/healthy; sleep 30; rm -f /tmp/healthy;sleep 3600"]
livenessProbe:
exec:
command: ["test","-e","/tmp/healthy"]
initialDelaySeconds: 2 (延迟探测)
periodSeconds: 3 (探测频率,默认10s)
liveness-httpget.yaml 容器存活 httpGet 示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
apiVersion: v1
kind: Pod
metadata:
name: liveness-httpget-pod
namespace: default
spec:
containers:
- name: liveness-httpget-container
image: ikubernetes/myapp:v1
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
livenessProbe:
httpGet:
port: http
path: /index.html
initialDelaySeconds: 2
periodSeconds: 3

ports 可以删除,可以直接在httpGet中port后使用端口

readiness-httpget.yaml 容器就绪 httpGet 示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
apiVersion: v1
kind: Pod
metadata:
name: readiness-httpget-pod
namespace: default
spec:
containers:
- name: readiness-httpget-container
image: ikubernetes/myapp:v1
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
readinessProbe:
httpGet:
port: http
path: /index.html
initialDelaySeconds: 2
periodSeconds: 3