Application Health: Liveness, Readiness & Startup Probes
Just because a container is running does not mean your application is actually working. Your app could be stuck in an infinite loop, waiting on a deadlocked database connection, or still loading heavy files into memory. By default, Kubernetes only checks if the container process is alive.
To build truly self-healing systems, you must teach Kubernetes how to check the real health of your app. That is where Probes come in. With the right health checks, Kubernetes can automatically restart frozen pods, stop sending user traffic to busy pods, and hold back bad deployments before they break production.
- The exact difference between
Startup,Readiness, andLivenessprobes. - How the Kubernetes
kubeletmonitors your pods and reacts when a check fails. - How to write custom health check endpoints in an ASP.NET Core (C#) Web API.
- How to configure all three probes cleanly inside a Kubernetes Deployment YAML file.
- Critical production mistakes to avoid (like checking your database inside a Liveness probe).
1. The Three Types of Kubernetes Probes
Think of a restaurant opening for dinner. First, the kitchen needs time to turn on the ovens and prep the food (Startup). Next, the host checks if tables are clean and ready before letting customers sit down (Readiness). Finally, the manager checks throughout the night to make sure the kitchen hasn't caught fire or completely frozen up (Liveness).
| Probe Type | Question It Answers | What Happens If It Fails? | Best Use Case |
|---|---|---|---|
| Startup Probe | Has the app finished booting up? | Kubelet kills and restarts the container. Blocks Liveness & Readiness until it passes. | Slow-starting apps (legacy services, ML models loading into RAM, heavy cache warmups). |
| Readiness Probe | Is the app ready to handle user requests right now? | Kubernetes removes the Pod IP from the Service. No restart happens. | Zero-downtime deployments, temporary database outages, or heavy background load. |
| Liveness Probe | Is the app still alive, or is it frozen/deadlocked? | Kubelet kills and restarts the container automatically. | Recovering from deadlocks, memory leaks, or unresponsive threads. |
How Kubernetes Runs These Checks
You can tell Kubernetes to check your app using three main methods:
- HTTP GET (
httpGet): Most common for Web APIs. Kubernetes sends an HTTP request to a path like/health/live. Any status code between200and399means healthy. - TCP Socket (
tcpSocket): Kubernetes tries to open a TCP connection on a specific port (like port5432for PostgreSQL). If the port opens, it is healthy. - Exec Command (
exec): Kubernetes runs a shell command inside the container (likecat /tmp/healthy). An exit code of0means healthy.
2. How Kubelet Monitors Your Pod (Animated Workflow)
The kubelet is the agent running on every Kubernetes worker node. It is the component that actually pings your container, tracks failures, and decides whether to cut off traffic or restart the container.
Kubernetes Probe Lifecycle & Traffic Control
Kubelet runs the Startup probe first. Once the app boots, Readiness controls whether the Kubernetes Service sends user traffic to the pod, while Liveness restarts the container if it stops responding.
3. Writing Custom Health Checks in Your App (C# / .NET)
Before configuring Kubernetes, your application needs to expose clean health endpoints. In ASP.NET Core, you can separate your checks using tags so that Liveness stays super fast and lightweight, while Readiness checks your external dependencies like SQL Server or Redis.
Example 1: Custom Health Checks in Program.cs (.NET 8 / .NET 9)
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
var builder = WebApplication.CreateBuilder(args);
// 1. Register health checks with specific tags
builder.Services.AddHealthChecks()
// Lightweight check for Liveness (no external calls)
.AddCheck("self", () => HealthCheckResult.Healthy("App is alive"), tags: new[] { "live" })
// Deep check for Readiness (checks database or cache)
.AddCheck<DatabaseHealthCheck>("sql_database", tags: new[] { "ready" });
var app = builder.Build();
// 2. Map separate endpoints for Kubernetes
// Liveness: Only runs checks tagged with "live"
app.MapHealthChecks("/health/live", new HealthCheckOptions
{
Predicate = check => check.Tags.Contains("live")
});
// Readiness: Only runs checks tagged with "ready"
app.MapHealthChecks("/health/ready", new HealthCheckOptions
{
Predicate = check => check.Tags.Contains("ready")
});
// Startup: Confirms the web server is up and listening
app.MapGet("/health/startup", () => Results.Ok("Started"));
app.Run();
// 3. Custom Readiness Check class
public class DatabaseHealthCheck : IHealthCheck
{
public async Task<HealthCheckResult> CheckHealthAsync(
HealthCheckContext context,
CancellationToken cancellationToken = default)
{
bool isDbConnected = await PingDatabaseAsync(cancellationToken);
return isDbConnected
? HealthCheckResult.Healthy("Database is reachable.")
: HealthCheckResult.Unhealthy("Cannot connect to Database.");
}
private Task<bool> PingDatabaseAsync(CancellationToken ct) => Task.FromResult(true);
}
Expected HTTP response when healthy
HTTP/1.1 200 OK Content-Type: text/plain Healthy
/health/* endpoints. The Kubernetes kubelet does not have a user login token, so it will get a 401 Unauthorized error and think your app is dead!4. Configuring Probes in Kubernetes YAML
Now that our API exposes /health/startup, /health/ready, and /health/live, we wire them into our Kubernetes Deployment manifest.
Example 2: Production-Ready Kubernetes Deployment (deployment.yaml)
apiVersion: apps/v1
kind: Deployment
metadata:
name: order-api
spec:
replicas: 3
selector:
matchLabels:
app: order-api
template:
metadata:
labels:
app: order-api
spec:
containers:
- name: order-api
image: shrashstudio/order-api:1.0
ports:
- containerPort: 8080
# 1. STARTUP PROBE: Gives the app up to 150 seconds (30 * 5s) to boot
startupProbe:
httpGet:
path: /health/startup
port: 8080
failureThreshold: 30
periodSeconds: 5
# 2. READINESS PROBE: Controls user traffic flow
readinessProbe:
httpGet:
path: /health/ready
port: 8080
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 3
# 3. LIVENESS PROBE: Restarts the container if it freezes
livenessProbe:
httpGet:
path: /health/live
port: 8080
periodSeconds: 15
timeoutSeconds: 2
failureThreshold: 3
Checking probe status with kubectl
$ kubectl describe pod order-api-7f8b9c6d4-x2k9p Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Started 2m kubelet Started container order-api Warning Unhealthy 1m kubelet Readiness probe failed: HTTP probe failed with statuscode: 503 Normal Ready 45s kubelet Container order-api is ready to receive traffic
Understanding the Key Probe Settings
| Setting | What It Controls | Recommended Starting Value |
|---|---|---|
initialDelaySeconds |
How long to wait after container start before the first check. (Often not needed if you use a Startup Probe). | 0 (when using Startup Probe) |
periodSeconds |
How often (in seconds) kubelet runs the check. | 10 to 15 seconds |
timeoutSeconds |
How long to wait for a response before counting the check as failed. | 2 to 5 seconds |
failureThreshold |
How many failures in a row before Kubernetes takes action (removes traffic or restarts). | 3 (for Liveness/Readiness), 30 (for Startup) |
5. Step-by-Step Execution Breakdown
Here is what happens behind the scenes when you push a new version of your app to the cluster:
startupProbe every 5 seconds. Liveness and Readiness probes are completely paused so they don't accidentally kill a slow-starting app./health/startup returns 200 OK, Kubelet stops running the Startup probe forever for that container and activates both Readiness and Liveness probes./health/ready. If your database connection is healthy, it returns 200 OK. Kubernetes adds the new Pod's IP to the Service load balancer and starts terminating one of the old Pods./health/ready keeps returning 503, Kubernetes holds back the rollout. Your old, working Pods stay alive, and your users never see an outage!6. Hands-On Practice
Deploy the YAML above to a local cluster (like Minikube or Docker Desktop). Change the DatabaseHealthCheck to return HealthCheckResult.Unhealthy() and run kubectl get pods.
Hint: Watch the READY column. It will stay at 0/1, and RESTARTS will remain 0.
Add a test endpoint /break-app that flips a boolean flag so /health/live starts returning 500 Internal Server Error.
Expected result: After 3 failed checks (45 seconds), run kubectl get pods and verify that the RESTARTS counter increases by 1 and the app recovers automatically.
Add a Thread.Sleep(25000) before app.Run() to simulate a heavy ML model loading into memory. First, deploy it with only a Liveness probe (periodSeconds: 5, failureThreshold: 3) and watch it enter a CrashLoopBackOff. Then add a startupProbe to fix it.
Hint: Ensure failureThreshold * periodSeconds on the Startup probe is greater than 25 seconds.
7. Interview Questions
Answer: A Liveness probe checks if the application is alive; if it fails, Kubernetes restarts the container. A Readiness probe checks if the application is ready to accept traffic; if it fails, Kubernetes removes the Pod from the Service load balancer without restarting it.
Answer: initialDelaySeconds is a fixed guess. If your app takes 10 seconds to start today but 45 seconds under heavy load tomorrow, a fixed delay will either slow down every deployment or cause premature restarts. A Startup probe checks repeatedly until the app is up, then immediately hands over to Liveness and Readiness.
Answer: No. Restarting your application container will not fix a down database. Checking external dependencies in a Liveness probe causes unnecessary pod restarts and can trigger a cascading failure (thundering herd) when all pods reboot and hammer the database at once. Database checks belong in the Readiness probe.
Answer: During a rolling update, Kubernetes starts a new Pod and waits for its Readiness probe to pass before routing any user traffic to it and before shutting down an old Pod. If the new version is broken and fails the Readiness check, the rollout pauses automatically and users stay on the healthy old version.
Conclusion
Configuring Liveness, Readiness, and Startup probes is one of the highest-impact habits you can build as a cloud engineer. It takes only a few lines of code and YAML, yet it transforms your Kubernetes cluster from a basic container runner into a smart, self-healing platform.
Keep your Liveness checks lightweight, put your dependency checks in Readiness, and use Startup probes to protect slow-booting services. Once you master this pattern, your deployments will become safer, smoother, and far easier to sleep through at night.
Official Documentation
- Kubernetes Documentation – Configure Liveness, Readiness and Startup Probes
- Microsoft Learn – Health checks in ASP.NET Core
Upgradix by Shrash Studio – Learn Technology. Build Your Future.