Use Dropwizard Health Checks for Kubernetes Probes
Wire Dropwizard's health-check registry to Kubernetes liveness and readiness probes without exposing your admin port to the public internet.
25 Jul 2025, 19:37 UTC

The problem: your probe is passing, but the service is not
A Kubernetes liveness probe that only opens a TCP connection to your Dropwizard application port tells kubelet the process is alive. It does not tell you whether the application can actually serve requests. A readiness probe with the same blind spot can send traffic to a pod whose database connection pool is exhausted or whose message consumer has stopped. Dropwizard includes a health-check registry that can answer that question, but wiring it to kubelet requires care around ports, timeouts, and blocking calls.
What Dropwizard exposes
Dropwizard provides the HealthCheck interface. You implement check(), return Result.healthy() or Result.unhealthy("message"), and register it with environment.healthChecks().register("name", check). The admin servlet aggregates every registered check and serves JSON under the admin context path, commonly /healthcheck. If any check throws an exception or returns unhealthy, the endpoint returns a non-success status, typically 500.
Important version note: Dropwizard 2.x uses javax packages, while Dropwizard 3.x uses Jakarta EE and requires Java 17. The health-check API is stable, but imports and dependency coordinates differ. Check your build file before copying code.
Worked example: register a check and point kubelet at it
This example assumes Dropwizard 3.x. A check that verifies a database connection might look like this:
public class DatabaseHealthCheck extends HealthCheck {
private final DataSource dataSource;
public DatabaseHealthCheck(DataSource dataSource) { this.dataSource = dataSource; }
@Override
protected Result check() throws Exception {
try (var connection = dataSource.getConnection()) {
return connection.isValid(2) ? Result.healthy() : Result.unhealthy("connection validation failed");
} catch (SQLException e) {
return Result.unhealthy(e.getMessage());
}
}
}Register it in your application class:
environment.healthChecks().register("database", new DatabaseHealthCheck(dataSource));Run the application locally and request the admin endpoint to confirm behavior:
# Run in your local terminal where the Dropwizard app is listening
curl -i http://localhost:8081/healthcheckExpected check: a healthy system returns HTTP 200 and JSON listing each registered check. If you temporarily register a check that returns Result.unhealthy() and restart, the same endpoint should return a non-200 status. Do not leave the failing check in production.
Kubernetes probe configuration
Dropwizard usually binds its admin connector to a separate port from the application port, for example 8081 versus 8080. Point the kubelet probes at the admin port and health-check path:
ports:
- name: http
containerPort: 8080
- name: admin
containerPort: 8081
readinessProbe:
httpGet:
path: /healthcheck
port: admin
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
livenessProbe:
httpGet:
path: /healthcheck
port: admin
initialDelaySeconds: 60
periodSeconds: 30
timeoutSeconds: 5Run kubectl describe pod <pod-name> to confirm probe events show Ready after the initial delay and no repeated Unhealthy warnings.
Keep the admin port off the public internet
The admin endpoint can reveal thread stacks, metrics, and configuration details. Bind the admin connector to an internal interface or use a Kubernetes NetworkPolicy so only kubelet and cluster-internal traffic can reach it. Do not publish the admin port in a public LoadBalancer or NodePort service.
Trade-offs and limitations
- Synchronous checks. Dropwizard runs each
check()synchronously when the endpoint is requested. A slow database call or external HTTP request inside a check blocks the admin thread and can delay probe responses. IftimeoutSecondsis too short, kubelet marks the probe failed and may restart the container. - Cascading failures. A readiness probe that fails because a downstream dependency is slow removes the pod from service. A liveness probe that fails for the same reason kills and restarts it, which can amplify an outage across replicas.
- Version drift. Admin context paths and status codes differ between Dropwizard 1.x, 2.x, and 3.x. Verify the exact path and status for your running version rather than assuming
/healthcheckalways returns 500 on failure.
Practical way to check the result
Deploy the probe configuration, then run a failing check in a staging namespace. Confirm that kubelet stops sending traffic to the pod for readiness or restarts it for liveness only after the configured failure threshold. Restore the healthy check and verify the pod recovers without manual intervention.
Closing
Dropwizard health checks are a good signal for Kubernetes probes because they reflect application-level health, not just process liveness. Map them to the admin port, isolate that port from public traffic, keep checks fast, and choose timeouts that tolerate brief dependency slowness without triggering restarts.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.