Configuring Liveness Probes for Containers
Liveness Probe Configuration Options
When configuring liveness probes for your containers, you can specify the following options:
httpGet
: Performs an HTTP GET request to a specific path and port.
tcpSocket
: Attempts to open a TCP connection to a specific port.
exec
: Executes a command inside the container and checks the exit code.
You can also configure additional settings, such as:
initialDelaySeconds
: The number of seconds to wait before performing the first probe.
periodSeconds
: The frequency (in seconds) at which the probe should be performed.
timeoutSeconds
: The number of seconds after which the probe times out.
failureThreshold
: The number of consecutive failures before the container is considered unhealthy.
successThreshold
: The number of consecutive successes before the container is considered healthy.
Example: Configuring an HTTP GET Liveness Probe
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
- name: my-app
image: my-app:v1
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 30
periodSeconds: 5
timeoutSeconds: 10
failureThreshold: 3
In this example, the liveness probe is configured to perform an HTTP GET request to the /healthz
endpoint on port 8080. The probe will start 30 seconds after the container is launched and will be executed every 5 seconds. If the probe times out after 10 seconds or fails 3 consecutive times, the container will be restarted.
Example: Configuring a TCP Socket Liveness Probe
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
- name: my-app
image: my-app:v1
livenessProbe:
tcpSocket:
port: 3306
initialDelaySeconds: 15
periodSeconds: 10
failureThreshold: 5
In this example, the liveness probe is configured to attempt a TCP connection to port 3306. The probe will start 15 seconds after the container is launched and will be executed every 10 seconds. If the probe fails 5 consecutive times, the container will be restarted.
Example: Configuring an Exec Liveness Probe
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
- name: my-app
image: my-app:v1
livenessProbe:
exec:
command:
- /bin/check_app.sh
initialDelaySeconds: 45
periodSeconds: 15
successThreshold: 1
In this example, the liveness probe is configured to execute the /bin/check_app.sh
script inside the container. The probe will start 45 seconds after the container is launched and will be executed every 15 seconds. If the script returns a non-zero exit code, the probe is considered a failure, and the container will be restarted.