Actuator and health checks
Expose health, metrics and info endpoints safely, and wire them to Kubernetes probes.
Open this lesson in the learning hubKey points
- Add
spring-boot-starter-actuatorand you get operational endpoints under/actuator. - Only
healthis exposed over HTTP by default. Opt the others in explicitly — they leak internals. /actuator/healthaggregates contributors: database, disk space, Redis, and any you add.- Enable probes for
/actuator/health/livenessand/readiness. Failing readiness pulls the pod out of rotation. - Never expose
env,heapdumporconfigpropspublicly. Put actuator on a separate port or behind auth. - Add
micrometer-registry-prometheusand/actuator/prometheusserves scrapeable metrics.
Example
management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus # explicit allow-list
endpoint:
health:
show-details: when_authorized
probes:
enabled: true # adds /health/liveness and /health/readiness
server:
port: 9090 # separate port: keep ops traffic off the public one
metrics:
tags:
application: ${spring.application.name}
# Custom check:
# @Component
# class PaymentGatewayHealth implements HealthIndicator {
# public Health health() {
# return gateway.ping() ? Health.up().build()
# : Health.down().withDetail("gateway", "unreachable").build();
# }
# }
Health endpoints are for your platform, not the public internet — expose deliberately.
This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Spring Boot course, and every lesson in it is listed on the Spring Boot contents page.