Applying Liveness Probe Configurations
Now that you have a good understanding of Liveness Probes and how to configure them, let's explore how to apply these configurations to your Kubernetes deployments.
Defining Liveness Probes in Kubernetes Manifests
To apply Liveness Probe configurations, you need to include the livenessProbe
field in your container's specification within the Kubernetes manifest (e.g., Deployment, StatefulSet, or DaemonSet). Here's an example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-container
image: my-app:v1
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
In this example, the Liveness Probe is configured to perform an HTTP GET request to the /healthz
endpoint on port 8080 every 10 seconds. The probe will wait 30 seconds before the first check, and it will be considered failed if it fails 3 consecutive times.
Verifying Liveness Probe Behavior
You can verify the behavior of your Liveness Probes by observing the container logs or using the kubectl describe
command to view the probe's status and events. If a container becomes unhealthy and the Liveness Probe fails, Kubernetes will automatically restart the container.
$ kubectl describe pod my-app-123456-abcde
...
Liveness: http-get http://:8080/healthz delay=30s timeout=5s period=10s #success=1 #failure=3
Liveness Probe Status: Failure
Liveness Probe Messages:
HTTP probe failed with statuscode: 500
By applying and verifying your Liveness Probe configurations, you can ensure that your Kubernetes-based applications are continuously monitored and automatically recovered when necessary, improving the overall reliability and availability of your services.