Sub topic 11
Using a separate management port and base path
This chapter assumes you can add Actuator to a Spring Boot project, expose endpoints with management.endpoints.web.exposure.include, and edit application.yml. You should also know the basics of HTTP ports and paths. Securing endpoints is covered in its own chapter, so here we only look at where Actuator listens.
Why move Actuator
By default, Actuator endpoints share the application's server port and live under /actuator. That is simple, but it has costs:
- Any firewall or ingress rule that exposes your application also exposes the Actuator paths.
- A load balancer that routes traffic by port cannot tell public traffic from operational traffic.
- Business security rules and Actuator rules end up in the same URL space.
Moving Actuator to its own port lets you open port 8080 to users and keep port 9090 reachable only from your monitoring network or your cluster.
Setting a management port
Set management.server.port to serve Actuator from a separate port.
server:
port: 8080
management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus
server:
port: 9090With this configuration:
http://localhost:8080/actuator/healthreturns 404, because the main server no longer serves Actuator.http://localhost:9090/actuator/healthreturns the health result.
Spring Boot starts a second embedded web server (a child context) for the management port. Your application controllers are not available on it.
Binding to a specific address
A different port still listens on all interfaces by default. To accept only local connections, set management.server.address.
management:
server:
port: 9090
address: 127.0.0.1This suits a sidecar agent on the same host that scrapes metrics. It does not suit Kubernetes probes, because the kubelet calls the pod's IP address rather than the loopback address. In a pod, leave the address unset and restrict access with a network policy.
Changing the base path
Two properties change the URL layout:
management.endpoints.web.base-pathreplaces the/actuatorprefix.management.endpoints.web.path-mapping.<id>renames a single endpoint.
management:
endpoints:
web:
base-path: /internal
path-mapping:
health: status
exposure:
include: health,info,prometheusThe health endpoint is now at /internal/status, and the Prometheus endpoint is at /internal/prometheus. Changing the path hides endpoints from casual scanning, but it is not a security control. Treat it as tidiness only.
If you set management.endpoints.web.base-path: /, endpoints are served from the root. This is allowed only when the management server uses a different port, because otherwise the endpoints could clash with your application's own mappings.
What changes for clients
Anything that calls Actuator must follow the new location. Update these:
| Client | What to update |
|---|---|
| Prometheus scrape config | `metrics_path` and the target port |
| Kubernetes probes | `port` and `path` in the probe definition |
| Load balancer health checks | Port and path |
| Docker `HEALTHCHECK` or scripts | The curl URL |
For example, a Prometheus job for the configuration above looks like this:
scrape_configs:
- job_name: orders-service
metrics_path: /internal/prometheus
static_configs:
- targets: ["orders:9090"]Common errors
- 404 on the old URL. After setting a management port, the main port no longer serves Actuator. Check which port the request is hitting.
- Probes fail after deployment. The container exposes 8080, but the probe still targets it. Point the probe at the management port, and make sure the pod declares that port.
- Endpoint missing. A path change does not change exposure. The endpoint must still be listed in
include. - Security rules not applied. The management port runs in a separate context, so a security setup built only for application paths may not cover it. Check it with a request that has no credentials.
Exercise
An application sets server.port: 8080, management.server.port: 9090, and management.endpoints.web.base-path: /ops, and exposes health. What is the URL of the health endpoint, and what does http://localhost:8080/ops/health return?
Show answer
The health endpoint is at http://localhost:9090/ops/health. The request to port 8080 returns 404, because the main server no longer serves Actuator endpoints.
Exercise
A Kubernetes readiness probe worked until you added management.server.port: 9090. The probe still targets port 8080 and now fails. What two changes fix it?
Show answer
Change the probe's port to 9090, and declare container port 9090 in the pod spec. Keep the path consistent with the base path, for example /actuator/health/readiness.