Introduction
Probing in general means inspecting or monitoring. Health probing in Kubernetes is nothing but monitoring the health of Kubernetes pods and containers.
Health probing can be done in three ways.
Executing commands inside containers periodically
Via HTTP Get request
Or by checking TCP Socket
and health probes are of 3 types,
Startup Probe
Readiness Probe
Liveliness probe
Kubernetes continuously checks application health using health probes, which are configured at the container level inside a Pod. These probes help Kubernetes decide:
When to restart a container
When to send or stop traffic
Whether an application has started successfully
Ways to Perform Health Probing in Kubernetes
Kubernetes supports three mechanisms to perform health checks:
1. Executing Commands Inside the Container
Kubernetes periodically runs a command inside the container. If the command exits with code 0 β probe succeeds else Any non-zero exit code means probe fails
livenessProbe:
exec:
command:
- sh
- -c
- cat /tmp/healthy
initialDelaySeconds: 20
periodSeconds: 10Here the probe checks whether the file /tmp/healthy exists. If not, the probe fails.
2. HTTP GET Request
Kubernetes sends an HTTP request to a specified endpoint.
Status codes 200β399 means success In case of Web applications exposing /health, /ready, or /status endpoints.
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 5The container is marked Ready only when /health responds successfully.
3. TCP Socket Check
Kubernetes checks whether a TCP port is open.
Successful TCP connection means probe succeeds and Connection failure refers to probe fails Using this in Databases or services that donβt expose HTTP endpoints.
readinessProbe:
tcpSocket:
port: 3306
initialDelaySeconds: 15
periodSeconds: 10Kubernetes verifies whether the application is listening on port 3306.
Types of Health Probes in Kubernetes
Kubernetes provides three types of health probes, each serving a different purpose.
1. Startup Probe
A Startup Probe checks whether the application has started successfully. Some applications take a long time to start. Without a startup probe, the liveness probe might kill the container too early. It Runs only during startup If it fails β container is restarted Once it succeeds β liveness and readiness probes begin
startupProbe:
httpGet:
path: /startup
port: 8080
failureThreshold: 30
periodSeconds: 10Kubernetes allows up to 5 minutes (30 Γ 10s) for the app to start.
2. Readiness Probe
A Readiness Probe checks whether the container is ready to accept traffic. If it fails then Pod is marked NotReady and Traffic is stopped, but Container is NOT restarted. Using in Application warm-up, Dependency failures (DB, cache, APIs) or Controlling rolling deployments.
readinessProbe:
httpGet:
path: /ready
port: 8080
periodSeconds: 5Traffic is routed to the Pod only when /ready responds successfully.
3. Liveness Probe
A Liveness Probe checks whether the application is still running correctly. If it fails then Kubernetes restarts the container
livenessProbe:
httpGet:
path: /live
port: 8080
initialDelaySeconds: 30
periodSeconds: 10If /live fails repeatedly, Kubernetes restarts the container.