Kubernetes Probe Basics
What are Kubernetes Probes?
Kubernetes probes are diagnostic tools used to determine the health and status of containers running in a pod. They help Kubernetes understand whether an application is running correctly and can automatically take actions to maintain application reliability.
Types of Kubernetes Probes
There are three primary types of probes in Kubernetes:
Probe Type |
Purpose |
Action Taken |
Liveness Probe |
Checks if container is running |
Restarts container if fails |
Readiness Probe |
Determines if container is ready to serve requests |
Removes pod from service load balancing |
Startup Probe |
Verifies if application has successfully started |
Prevents other probes from running until startup succeeds |
Probe Mechanisms
Probes can be configured using three primary mechanisms:
graph TD
A[Probe Mechanisms] --> B[HTTP GET Request]
A --> C[TCP Socket Check]
A --> D[Command Execution]
HTTP GET Request
Checks container health by sending HTTP requests to a specified endpoint.
Example configuration:
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 15
periodSeconds: 10
TCP Socket Check
Verifies container connectivity by attempting to establish a TCP connection.
Example configuration:
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
Command Execution
Runs a command inside the container to determine health status.
Example configuration:
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 10
periodSeconds: 5
Probe Configuration Parameters
Key configuration parameters for probes include:
initialDelaySeconds
: Delay before first probe
periodSeconds
: Frequency of probe checks
timeoutSeconds
: Maximum time for probe response
successThreshold
: Minimum consecutive successes
failureThreshold
: Maximum consecutive failures
Best Practices
- Use appropriate probe types for different scenarios
- Set realistic timeout and delay values
- Implement meaningful health check endpoints
- Avoid complex probe logic
LabEx Recommendation
When learning Kubernetes probes, practice configuring and testing different probe scenarios in a controlled environment like LabEx Kubernetes Playground to gain hands-on experience.