# 容器探测
- 用于检测容器中实例是否正常工作
- 通过执行某些代码,判断结果是否达到预期
- 未达到预期k8s会问题实例干掉
# 两种探测容器 探针
- liveness probe 存活性探测
- 是否正常状态,不正常重启
- k8s尝试重启不正常的
- readliness probe 就绪性探测
- pod是否可以对外服务,如果不能,不会转发流量
- 某些pod需要时间准备,就绪后才可以
- k8s尝试等待
# 探测配置
- command
- tcp
- httpGet
~~~ yaml
livenessProbe:
exec:
command:
- cat
- /tmp/helthy
---
livenessProbe:
tcpSocket:
port: 8080
---
livenessProbe:
httpGet:
path: /
port: 80
host: 192.168.0.1
scheme: HTTP # http 或https
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 容器探测其他配置项
- exec
- tcpSocket
- httpGet
- initialDelaySeconds: int
- 延时一段时间后再开始探测循环
- timeoutSeconds: int
- 探测超时 默认 1s
- periodSeconds: int
- 循环周期长度
- failureThreshold: int
- 探测多少次才算失败, 默认3 最小 1
- successThreshold: int
- 连续探测几次才算成功,默认1