探针类型:
livenessProbe(存活检查):如果检查失败,将杀死容器,根据Pod的RestartPolicy来操作
readinessProbe(就绪检查):如果检查失败,Kubernetes会把Pod从service endpoints中剔除
检查方法:
httpGet:发送HTTP请求,返回200-400范围状态码为成功;
exec:执行Shell命令返回状态码是0为成功;
tcpSocket:发起TCP Socket建立成功;
探针演示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| apiVersion: v1 kind: Pod metadata: labels: test: liveness name: liveness-exec spec: containers: - name: liveness image: busybox args: - /bin/sh - -c - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600 livenessProbe: exec: command: - cat - /tmp/healthy initialDelaySeconds: 5 # 容器启动5秒后开始健康检查; periodSeconds: 5 # 检查周期,每5秒检查一次 readinessProbe: exec: command: - cat - /tmp/healthy initialDelaySeconds: 5 periodSeconds: 5
# 官网:https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
|