Register health checks:
builder.Services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy())
.AddNpgSql(builder.Configuration.GetConnectionString("Db")!);Map the endpoints:
app.MapHealthChecks("/health/live", new HealthCheckOptions
{
Predicate = check => check.Name == "self"
});
app.MapHealthChecks("/health/ready");Use /health/live for Kubernetes liveness probes and /health/ready for readiness probes. The readiness probe includes the database check so traffic isn’t routed until the DB is reachable.