Kubernetes Probes: Liveness, Readiness, and Startup
Health probes ensure your applications are running correctly and receiving traffic appropriately.
Probe Types
| Probe | Purpose | Failure Action |
|---|---|---|
| Liveness | Is container healthy? | Restart container |
| Readiness | Is container ready for traffic? | Remove from Service |
| Startup | Has container started? | Kill container |
Probe Mechanisms
HTTP Probe
livenessProbe:
httpGet:
path: /health
port: 8080
httpHeaders:
- name: Custom-Header
value: Awesome
initialDelaySeconds: 5
periodSeconds: 10
failureThreshold: 3TCP Probe
livenessProbe:
tcpSocket:
port: 3306
initialDelaySeconds: 15
periodSeconds: 20Exec Probe
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5Probe Configuration
| Parameter | Description | Default |
|---|---|---|
initialDelaySeconds | Delay before first probe | 0 |
periodSeconds | How often to probe | 10 |
timeoutSeconds | Probe timeout | 1 |
successThreshold | Min consecutive successes | 1 |
failureThreshold | Failures before action | 3 |
Liveness Probe
Restarts container if unhealthy:
apiVersion: v1
kind: Pod
metadata:
name: liveness-demo
spec:
containers:
- name: app
image: my-app
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 3Readiness Probe
Removes pod from service if not ready:
spec:
containers:
- name: app
image: my-app
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5Startup Probe
For slow-starting applications. Disables other probes until success:
spec:
containers:
- name: app
image: slow-starter
startupProbe:
httpGet:
path: /started
port: 8080
failureThreshold: 30
periodSeconds: 10
livenessProbe:
httpGet:
path: /healthz
port: 8080Complete Example
apiVersion: v1
kind: Pod
metadata:
name: probe-demo
spec:
containers:
- name: app
image: my-app
ports:
- containerPort: 8080
startupProbe:
httpGet:
path: /started
port: 8080
failureThreshold: 30
periodSeconds: 10
livenessProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 8080
periodSeconds: 5Best Practices
- Always configure readiness probes
- Use startup probe for slow apps
- Keep probe endpoints lightweight
- Don’t check dependencies in liveness
- Set appropriate thresholds
Practice Health Probes
Probe configuration appears in CKAD exams. Practice at Sailor.sh.