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> 启动时间避免误杀
periodSeconds5~10检查频率
timeoutSeconds1~3超时时间
failureThreshold3连续失败次数
successThreshold1连续成功次数

本章总结

核心要点

  1. K8s 探针需要完整配置:启动、存活、就绪
  2. 参数要根据应用调优:避免误杀和延误
  3. 探针路径要幂等:多次检查不影响应用状态