Configuring Kubernetes Probes
Kubernetes supports three types of probes: HTTP Probe, TCP Probe, and Command Probe. Each type of probe has its own set of configuration parameters that can be used to customize the health check behavior.
HTTP Probe
The HTTP Probe checks the health of a container by sending an HTTP request to a specified endpoint. Here's an example configuration:
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
- name: my-container
image: my-app:v1
readinessProbe:
httpGet:
path: /ready
port: 8080
httpHeaders:
- name: Custom-Header
value: Awesome
initialDelaySeconds: 5
periodSeconds: 10
In this example, the Readiness Probe checks the /ready
endpoint on port 8080 every 10 seconds. The httpHeaders
field allows you to set custom headers in the HTTP request.
TCP Probe
The TCP Probe checks the health of a container by attempting to establish a TCP connection to a specified port. Here's an example configuration:
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
- name: my-container
image: my-app:v1
livenessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
In this example, the Liveness Probe checks the availability of the container by attempting to establish a TCP connection on port 8080 every 10 seconds.
Command Probe
The Command Probe checks the health of a container by executing a command inside the container. The command should return a successful exit code (0) if the container is healthy. Here's an example configuration:
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
- name: my-container
image: my-app:v1
startupProbe:
exec:
command:
- /app/startup-check.sh
initialDelaySeconds: 5
periodSeconds: 10
In this example, the Startup Probe checks the health of the container by executing the /app/startup-check.sh
script every 10 seconds. The initialDelaySeconds
parameter tells Kubernetes to wait 5 seconds before starting the first Startup Probe check.