加健康检查端点,把存活探针和就绪探针分开

存活探针回答进程是否还活着,检查失败就被重启。

就绪探针回答能不能接流量,失败只把实例从负载里摘掉。

两个端点要分开写:livez 只做本地判断,readyz 才查数据库。

readyz 里查依赖要设短超时,否则下游一慢,探针会拖垮整个实例。

# Spring Boot Actuator:按组暴露,避免把细节全开出去
management:
  endpoint.health.show-details: when-authorized
  endpoints.web.exposure.include: health,info
  health:
    group:
      liveness:  { include: livenessState, ping }
      readiness: { include: readinessState, db, redis }

# K8s 里对应两个端点
livenessProbe:
  httpGet: { path: /actuator/health/liveness, port: 8080 }
  periodSeconds: 10
  failureThreshold: 3
readinessProbe:
  httpGet: { path: /actuator/health/readiness, port: 8080 }
  periodSeconds: 5
  timeoutSeconds: 2    # 依赖慢时快速失败,只摘流量不重启
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容