Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
DevOps & CI/CDbeginner

Health Check Endpoint

Share

Create health check and readiness endpoints

Works with OpenClaude

You are a DevOps engineer. The user wants to create health check and readiness endpoints for application monitoring and orchestration systems like Kubernetes.

What to check first

  • Current application framework (Express, Flask, FastAPI, Spring Boot, etc.)
  • Whether the app runs in Kubernetes or Docker Swarm
  • Existing metrics/monitoring infrastructure
  • Port availability for health endpoints (typically 8080, 3000, or 5000)

Steps

  1. Add a /health liveness endpoint that returns HTTP 200 with a simple status response—this tells orchestrators if the process is alive
  2. Add a /ready or /readiness endpoint that checks critical dependencies (database, cache, external APIs) and returns 503 if unavailable
  3. Return JSON with status, timestamp, and dependency checks (not plain text—JSON is parseable by monitoring tools)
  4. Ensure health endpoints don't require authentication (add them to security exclusions in your auth middleware)
  5. Keep health checks fast—set internal timeout to 2-5 seconds max, return failure immediately rather than hanging
  6. Use appropriate HTTP status codes: 200 for healthy, 503 Service Unavailable for unhealthy
  7. Configure your orchestrator's probe settings: Kubernetes uses livenessProbe (restart unhealthy containers) and readinessProbe (remove from load balancer)
  8. Log health check responses at debug level only to avoid log spam

Code

// Express.js health check endpoints
const express = require('express');
const app = express();

// Shared state for dependency health
let dbHealthy = true;
let cacheHealthy = true;

// Liveness probe—checks if process is running
app.get('/health', (req, res) => {
  res.status(200).json({
    status: 'alive',
    timestamp: new Date().toISOString(),
    uptime: process.uptime()
  });
});

// Readiness probe—checks if dependencies are ready
app.get('/ready', async (req, res) => {
  try {
    // Check database connection with timeout
    const dbCheck = checkDatabase().catch(() => false);
    const cacheCheck = checkCache().catch(() => false);
    
    const [dbOk, cacheOk] = await Promise.all([
      Promise.race([dbCheck, new Promise((_, reject) => 
        setTimeout(() => reject(new Error('timeout')), 3000)
      )])
    ]);
    
    const allHealthy = dbOk && cacheOk;
    
    const response = {
      status: allHealthy ? 'ready' : 'not_ready',
      timestamp: new Date().toISOString(),
      checks: {
        database: { status: dbOk ? 'ok' : 'failed' },
        cache: { status: cacheOk ? 'ok' : 'failed' }
      }
    };

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
devopshealth-checkmonitoring

Install command:

curl -o ~/.claude/skills/health-check-endpoint.md https://claude-skills-hub.vercel.app/skills/devops/health-check-endpoint.md

Related DevOps & CI/CD Skills

Other Claude Code skills in the same category — free to download.

Want a DevOps & CI/CD skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.