dawdler 云原生 k8s 对接
dawdler 在既有 HealthIndicator 健康检测体系之上, 提供了 k8s 语义的 存活探针(/live) 与 就绪探针(/ready), 并与优雅停机链路打通, 停机第一时间摘流.
适用端: dawdler-server(独立健康检测端口)与 dawdler-client-plug-web(外部 Servlet 容器, 如 Tomcat).
1. 探针端点与状态码语义
| 端点 | 默认 uri | server 端配置键 | web 端配置键 | 判定 | 200 | 503 |
|---|---|---|---|---|---|---|
| 存活探针 | /live | dawdler.server.health.liveUri | dawdler.web.health.liveUri | 进程存活(不跑组件检查) | 存活 | - |
| 就绪探针 | /ready | dawdler.server.health.readyUri | dawdler.web.health.readyUri | 探针状态 + 组件健康聚合 | 就绪 | 启动中/停机摘流/组件DOWN |
/live不跑组件检查: 外部依赖(dataSource/jedis/rabbit/es/config)抖动不会引发 Pod 重启风暴, 只反映进程存活./ready与/health同语义地聚合组件健康(复用 server-conf.xml / web-conf.xml 的 health-check 组件开关), 并叠加进程级探针状态:STARTING(启动中) → 503READY(启动完成) → 组件健康 UP 时 200OUT_OF_SERVICE(停机摘流, 不可逆) → 503
- 响应体为
{"status":"UP|STARTING|OUT_OF_SERVICE"}. - 与
/health的差异: server 端/healthUP→200/其余→500; web 端/health恒 200(兼容既有监控, 保持不变). 探针端点统一用 k8s 语义的 200/503. - 鉴权: 与
/health共用 Basic Authentication(health-check 节点的 username/password), 探针请求需带Authorization头. - 前置条件: server 端需 health-check
check="on"才会开启健康端口; web 端/live//ready不受 health-check 开关影响(进程存活/探针状态始终可查), 但组件聚合部分仅在开启时生效.
配置键优先级与读取时机同 dawdler-config.yml 体系(-D > 环境变量 > yml properties: > 默认值), 详见dawdler-config-README.
2. k8s 探针配置示例
apiVersion: apps/v1
kind: Deployment
metadata:
name: order-service
spec:
template:
spec:
containers:
- name: order-service
ports:
- name: health
containerPort: 19001
livenessProbe:
httpGet:
path: /live
port: health
scheme: HTTPS # server 端 https 时; web 端用 HTTP
initialDelaySeconds: 30
periodSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /ready
port: health
scheme: HTTPS
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 3
lifecycle:
preStop:
exec:
command: ["sh", "dawdler.sh", "stop"] # server 端; web 端见下
terminationGracePeriodSeconds: 180
若 health-check 配置了 Basic Auth, 探针 httpGet 需增加:
httpGet:
path: /ready
port: health
httpHeaders:
- name: Authorization
value: "Basic amFja3NvbjpqYWNrc29uLnNvbmc=" # base64(username:password)