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

LivenessReadiness
QuestionIs the process stuck?Should it get traffic right now?
On failurethe orchestrator restarts itthe load balancer stops sending it requests
Checksthe process itselfrequired dependencies: database, cache, config loaded
Should fail when the database is down?noyes

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

HTTP
GET {{baseUrl}}/live
JavaScript
pm.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:

JavaScript
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:

  1. Run the health folder: everything 200.
  2. Stop the database: docker compose stop db.
  3. Run it again.
EndpointExpected with the database down
/livestill 200
/ready503, ideally saying which dependency
a normal API requesta clean 503, not a 500 with a stack trace
  1. Start the database. /ready should return to 200 on 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:

Terminal
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.