Advertisement
Advanced ASP.NET Core, Health Checks

How do you differentiate liveness and readiness health checks using tags, and why does Kubernetes treat these two probe types differently?

Short answer

Liveness checks answer 'is the process alive and not deadlocked' (a failure means the container should be restarted), while readiness checks answer 'is this instance ready to receive traffic' (a failure means temporarily remove it from the load balancer's rotation without…

Save ASP.NET Core mock interview
Advertisement
AModel answer
Liveness checks answer 'is the process alive and not deadlocked' (a failure means the container should be restarted), while readiness checks answer 'is this instance ready to receive traffic' (a failure means temporarily remove it from the load balancer's rotation without restarting it, useful during startup or brief downstream dependency issues) -- implemented by tagging individual health checks (AddCheck(..., tags: new[] { "ready" })) and configuring separate MapHealthChecks endpoints filtered by tag via the Predicate option, matched to Kubernetes' separate livenessProbe and readinessProbe configuration.
builder.Services.AddHealthChecks()
    .AddCheck<DatabaseHealthCheck>("database", tags: new[] { "ready" })
    .AddCheck("self", () => HealthCheckResult.Healthy(), tags: new[] { "live" });

app.MapHealthChecks("/health/live", new HealthCheckOptions { Predicate = c => c.Tags.Contains("live") });
app.MapHealthChecks("/health/ready", new HealthCheckOptions { Predicate = c => c.Tags.Contains("ready") });
Real-world example
A Kubernetes deployment configures livenessProbe against /health/live (checking only that the process itself is responsive, restarting on failure) and readinessProbe against /health/ready (checking database connectivity, temporarily pulling the pod from service rotation on failure without restarting it), correctly distinguishing 'crash and restart me' from 'temporarily stop sending me traffic.'
Likely follow-ups
  • What happens if you incorrectly use the same check for both liveness and readiness?
  • How would a slow-starting dependency (like a cache warming up) be handled differently between the two probe types?
Related topics