Probes
A Probe is a diagnostic mechanism that Kubernetes uses to check the health of a container. They run periodically and report the status back to the kubelet. Based on the probe result, Kubernetes can decide to:
Restart a container
Stop routing traffic to a container
Mark the Pod as ready or not ready
Types of Probes
Liveness probe
Checks if the container is still running properly.
If it fails, Kubernetes restarts the container.
Example: an app is running but deadlocked → liveness probe fails → kubelet restarts it.
Example
...
spec:
template:
...
spec:
containers:
- name: myapp-container
image: nginx:1.25
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /healthz
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
Readiness probe
Checks if the container is ready to accept traffic.
If it fails, the Pod is marked unready → Service will stop sending traffic to it.
Example: your app takes 30 seconds to load caches. Until ready probe passes, no traffic is sent.
...
spec:
template:
...
spec:
containers:
- name: myapp-container
image: nginx:1.25
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /healthz
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
Startup probe
Checks if the container has started successfully.
Especially useful for apps with slow startup times.
Disables liveness and readiness checks until it succeeds.
Prevents Kubernetes from killing apps that just need more time to boot.
...
spec:
template:
...
spec:
containers:
- name: myapp-container
image: nginx:1.25
ports:
- containerPort: 80
startupProbe:
httpGet:
path: /healthz
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
Probe Actions
Probes can use one of these mechanisms to check health:
httpGet
Hits an HTTP endpoint in your container:
httpGet:
path: /healthz
port: 8080
tcpSocket
Tries to open a TCP connection:
tcpSocket:
port: 3306
exec
Runs a command inside the container:
exec:
command: ["cat", "/tmp/healthy"]
Probe Parameters
initialDelaySeconds
: how long to wait before starting checks.periodSeconds
: how often to run the probe.timeoutSeconds
: how long to wait before probe times out.successThreshold
: how many successes before marking healthy.failureThreshold
: how many failures before marking unhealthy.
Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 2
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: myapp:1.0
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
startupProbe:
httpGet:
path: /startup
port: 8080
failureThreshold: 30
periodSeconds: 10
Last updated