#Kubernetes 探针配置
K8s 探针的配置需要根据应用特性和依赖进行调优。
#完整配置示例
complete-probe-config.yaml
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- name: myapp
image: myapp:v1
# 启动探针:给予 5 分钟启动时间
startupProbe:
httpGet:
path: /health/started
port: 8080
failureThreshold: 60
periodSeconds: 5
# 存活探针:每 10 秒检查一次
livenessProbe:
httpGet:
path: /health/live
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
successThreshold: 1
# 就绪探针:每 5 秒检查一次
readinessProbe:
httpGet:
path: /health/ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 3
successThreshold: 1
# 资源限制
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"#探针配置调优
| 参数 | 建议值 | 说明 |
|---|---|---|
initialDelaySeconds | > 启动时间 | 避免误杀 |
periodSeconds | 5~10 | 检查频率 |
timeoutSeconds | 1~3 | 超时时间 |
failureThreshold | 3 | 连续失败次数 |
successThreshold | 1 | 连续成功次数 |
#本章总结
核心要点:
- K8s 探针需要完整配置:启动、存活、就绪
- 参数要根据应用调优:避免误杀和延误
- 探针路径要幂等:多次检查不影响应用状态