Skip to main content

dawdler Cloud-Native k8s Integration

On top of its existing HealthIndicator health check system, dawdler provides k8s-semantic liveness probes (/live) and readiness probes (/ready), and ties them into the graceful shutdown chain so traffic is drained the moment shutdown begins.

Applicable sides: dawdler-server (dedicated health check port) and dawdler-client-plug-web (external Servlet container such as Tomcat).

1. Probe endpoints and status code semantics​

EndpointDefault uriServer-side config keyWeb-side config keyDetermination200503
Liveness probe/livedawdler.server.health.liveUridawdler.web.health.liveUriProcess is alive (no component checks)Alive-
Readiness probe/readydawdler.server.health.readyUridawdler.web.health.readyUriProbe state + aggregated component healthReadyStarting / draining on shutdown / component DOWN
  • /live runs no component checks: flapping external dependencies (dataSource/jedis/rabbit/es/config) does not trigger a Pod restart storm; it reflects only whether the process is alive.
  • /ready aggregates component health with the same semantics as /health (reusing the health-check component switches in server-conf.xml / web-conf.xml) and layers the process-level probe state on top:
    • STARTING (starting) → 503
    • READY (startup complete) → 200 when component health is UP
    • OUT_OF_SERVICE (draining on shutdown, irreversible) → 503
  • The response body is {"status":"UP|STARTING|OUT_OF_SERVICE"}.
  • Difference from /health: on the server side /health returns 200 when UP and 500 otherwise; on the web side /health always returns 200 (for compatibility with existing monitoring, kept unchanged). The probe endpoints consistently use k8s semantics of 200/503.
  • Authentication: Basic Authentication is shared with /health (the username/password of the health-check node), so probe requests must carry an Authorization header.
  • Prerequisites: on the server side, health-check check="on" is required to open the health port; on the web side /live//ready are unaffected by the health-check switch (the process liveness/probe state is always queryable), but the component aggregation part only takes effect when it is enabled.

The priority and read timing of configuration keys are the same as the dawdler-config.yml system (-D > environment variables > yml properties: > default values); see dawdler-config-README for details.

2. k8s probe configuration example​

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 # Use HTTPS when the server side is https; use HTTP on the web side
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 side; see below for the web side
terminationGracePeriodSeconds: 180

If health-check is configured with Basic Auth, the probe httpGet needs to add:

httpGet:
path: /ready
port: health
httpHeaders:
- name: Authorization
value: "Basic amFja3NvbjpqYWNrc29uLnNvbmc=" # base64(username:password)

3. preStop graceful shutdown integration​

dawdler's design principle for draining traffic on shutdown: probes turn red before any resource is reclaimed. The first line of DawdlerServer.doShutdown() is ProbeStateManager.markShuttingDown(), so /ready immediately flips to 503 irreversibly, and only then does the reclamation chain begin (JMX deregistration / connection draining / component destruction, etc.).

The two trigger paths converge at the same point:

  1. preStop exec (recommended, shortest drain window): k8s first removes the Endpoint, then runs the preStop dawdler.sh stop (sending stop via tcp-shutdownPort; the source IP must be in the shutdownWhiteList) or the JMX shutdownGraceful() → traffic is drained immediately → the RPC side stops reading and keeps writing, draining in-flight requests (dawdler.server.graceful.timeout, 30s by default) → container components are destroyed → the process exits.
  2. SIGTERM (when there is no preStop): the JVM ShutdownHook calls shutdown(true); the drain action is the same, but kubelet updates Endpoints concurrently with a delay, so terminationGracePeriodSeconds is relied on to wait for Endpoint propagation.
ParameterDefault/exampleDescription
dawdler.server.graceful.timeout30sUpper bound on waiting to drain in-flight RPC requests
Web-side shutdownContainers wait120sLatch wait for graceful closure of container components in WebListener.contextDestroyed
terminationGracePeriodSeconds180s (example)k8s force-kill limit; should be >= preStop duration + the sum of the two above, with margin left for Endpoint removal propagation

That is: terminationGracePeriodSeconds > probe drain propagation (usually a few seconds) + RPC draining (30s) + container shutdown (120s) + buffer.

3.2 Web-side (external Tomcat) integration​

When the web application is deployed in an external Servlet container:

  • The first line of WebListener.contextDestroyed() drains traffic, and only then are components destroyed in reverse order; the probe endpoint (ViewFilter) can still respond 503 before that method returns.
  • For preStop it is recommended to use exec to call sh shutdown.sh (the Tomcat shutdown script): Tomcat receives the shutdown → contextDestroyed is triggered → /ready returns 503 → in-flight requests continue to drain through the Tomcat connector's graceful shutdown.
  • Without preStop, SIGTERM is translated by Tomcat's catalina.sh into the semantics of shutdown.sh, following the same path.
  • When multiple webapps coexist in the same Tomcat the probe state is process-level (single classloader scenario), so one webapp per Pod is recommended.

4. Probe state visibility (JMX)​

The dawdler-server ServerStatusMXBean adds read-only attributes:

AttributeDescription
Ready (boolean)Whether currently ready (false for both STARTING and OUT_OF_SERVICE)
ReadinessStatus (string)UP / STARTING / OUT_OF_SERVICE

They can be observed via jconsole / Prometheus jmx_exporter, and are useful for troubleshooting problems such as "slow startup" and "traffic draining not taking effect".

5. Manual verification​

Server side (with health-check enabled in server-conf.xml):

curl -k https://127.0.0.1:19001/live # 200 {"status":"UP"}
curl -k https://127.0.0.1:19001/ready # 200 {"status":"UP"}
sh dawdler.sh stop # Or JMX shutdownGraceful()
# During the shutdown window:
curl -k https://127.0.0.1:19001/ready # 503 {"status":"OUT_OF_SERVICE"}
curl -k https://127.0.0.1:19001/live # Still 200; the process is still draining

Web side (deployed to a local Tomcat):

curl http://localhost:8082/ready # 200
sh shutdown.sh # Tomcat shutdown
# During the shutdown window:
curl http://localhost:8082/ready # 503 {"status":"OUT_OF_SERVICE"}