🔄 Key Takeaways: Master liveness, readiness, and startup probes for graceful deployments and automatic recovery in Kubernetes.
Deployments causing downtime? Probes ensure your pods are ready before receiving traffic.
📋 Complete Probe Configuration
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0 # ✅ Zero downtime!
template:
spec:
containers:
- name: app
image: myapp:latest
ports:
- containerPort: 80
# 1. Startup Probe - Slow start protection
startupProbe:
httpGet:
path: /health
port: 80
failureThreshold: 30
periodSeconds: 10
# Total: 30 * 10 = 300 seconds max startup
# 2. Readiness Probe - Traffic control
readinessProbe:
httpGet:
path: /health/ready
port: 80
initialDelaySeconds: 5
periodSeconds: 5
failureThreshold: 3
# 3. Liveness Probe - Auto-recovery
livenessProbe:
httpGet:
path: /health
port: 80
initialDelaySeconds: 30
periodSeconds: 10
failureThreshold: 3
💡 .NET Health Checks
// Program.cs
builder.Services.AddHealthChecks()
.AddDbContextCheck<AppDbContext>("database")
.AddUrlGroup(new Uri("https://external-api.com"), "external-api")
.AddCheck("custom");
app.MapHealthChecks("/health", new HealthCheckOptions
{
ResponseWriter = async (context, report) =>
{
context.Response.ContentType = "application/json";
var result = new
{
status = report.Status.ToString(),
checks = report.Entries.Select(e => new
{
name = e.Key,
status = e.Value.Status.ToString(),
description = e.Value.Description
})
};
await context.Response.WriteAsJsonAsync(result);
}
});
📊 Probe Comparison
| Probe Type | Purpose | Failure Action | Best For |
|---|---|---|---|
| Startup | Slow start | Restart pod | Large images, migrations |
| Readiness | Traffic check | Remove from service | Dependencies, warmup |
| Liveness | Health check | Restart pod | Deadlocks, crashes |
