Test your API's health check endpoints before Kubernetes does
Health endpoints are the API your orchestrator, load balancer and uptime monitor call thousands of times a day. Nobody reviews them, and their bugs are expensive: a readiness check that never fails sends traffic to a service that can't reach its database; a liveness check that calls the database restarts every pod when the database blips. A small folder of tests catches both.
Liveness vs readiness
| Liveness | Readiness | |
|---|---|---|
| Question | Is the process stuck? | Should it get traffic right now? |
| On failure | the orchestrator restarts it | the load balancer stops sending it requests |
| Checks | the process itself | required dependencies: database, cache, config loaded |
| Should fail when the database is down? | no | yes |
The classic mistake is checking the database in liveness. The database restarts, every pod's liveness fails, every pod restarts at once, and a short outage becomes a long one.
The basic tests
GET {{baseUrl}}/livepm.test('alive', () => pm.response.to.have.status(200));
pm.test('fast', () => pm.expect(pm.response.responseTime).to.be.below(100));
pm.test('not cached', () => {
const cache = pm.response.headers.get('Cache-Control') || '';
pm.expect(cache).to.match(/no-store|no-cache/);
});Same for /ready. Health checks run often and with short timeouts (Kubernetes defaults to one second), so a slow one fails for no real reason.
What they shouldn't say
Health endpoints are often public by accident. Check that the body doesn't hand out a map of your system:
const body = pm.response.text();
pm.test('no internals in the health response', () => {
pm.expect(body).to.not.match(/password|postgres:\/\/|redis:\/\/|stack|Exception/i);
pm.expect(body).to.not.match(/\b10\.\d+\.\d+\.\d+\b|\b192\.168\./);
});A detailed dependency report is useful; put it behind authentication or on an internal port, and keep the public one to ok or a status code.
Break a dependency on purpose
The test that matters is the one with something broken. In a local docker-compose setup or a staging namespace:
- Run the health folder: everything
200. - Stop the database:
docker compose stop db. - Run it again.
| Endpoint | Expected with the database down |
|---|---|
/live | still 200 |
/ready | 503, ideally saying which dependency |
| a normal API request | a clean 503, not a 500 with a stack trace |
- Start the database.
/readyshould return to200on its own, without a restart.
Optional dependencies (a recommendations service, analytics) shouldn't fail readiness at all. The API should degrade, not disappear.
During shutdown
A well-behaved service fails readiness before it stops serving, so the load balancer drains it first. If you can, send a request to /ready right after sending the process SIGTERM: 503 while the API still answers is the right behaviour.
Watch them from outside too
Run the folder from CI after each deploy, and on a schedule:
requestarium run-collection "Platform" --folder "Health" --env Production --max-p95 200--max-p95 fails the run when the 95th percentile response time is above 200 ms, which catches a health check that has started doing real work.