Advertisement
Advanced Node.js, Cloud & DevOps

What is a health check endpoint, and how does an orchestrator like Kubernetes use liveness and readiness probes differently?

Short answer

Kubernetes distinguishes liveness probes (is the process alive and not deadlocked? failing restarts the container) from readiness probes (is the instance ready for traffic right now?

Save Node.js mock interview
Advertisement
AModel answer
Kubernetes distinguishes liveness probes (is the process alive and not deadlocked? failing restarts the container) from readiness probes (is the instance ready for traffic right now? failing just removes it from the load balancer temporarily, without restarting), since a temporarily overloaded but otherwise healthy instance should stop receiving traffic without a needless restart.
app.get('/healthz/live', (req, res) => res.status(200).send('OK'));

app.get('/healthz/ready', async (req, res) => {
  const dbOk = await checkDatabaseConnection();
  res.status(dbOk ? 200 : 503).send(dbOk ? 'Ready' : 'Not ready');
});
Real-world example
A service that temporarily loses its database connection fails its readiness probe (removed from traffic without a disruptive restart) while still passing liveness, rejoining traffic once the connection is restored.
Likely follow-ups
  • What's the risk of making the liveness probe check external dependencies rather than just the process's own health?
  • How do you tune failureThreshold and periodSeconds to avoid both false positives and slow detection?
Related topics