Liveness Probe — check if application is alive and needs restart.
1apiVersion: apps/v12kind: Deployment3metadata:4 name: myapp5spec:6 replicas: 37 template:8 spec:9 containers:10 - name: app11 image: myapp:latest12 livenessProbe:13 httpGet:14 path: /healthz15 port: 808016 httpHeaders:17 - name: X-Liveness18 value: "check"19 initialDelaySeconds: 1520 periodSeconds: 2021 timeoutSeconds: 522 successThreshold: 123 failureThreshold: 324---25# TCP liveness probe26apiVersion: apps/v127kind: Deployment28metadata:29 name: myapp-tcp30spec:31 template:32 spec:33 containers:34 - name: app35 image: myapp:latest36 livenessProbe:37 tcpSocket:38 port: 808039 initialDelaySeconds: 1540 periodSeconds: 2041---42# Exec liveness probe43apiVersion: apps/v144kind: Deployment45metadata:46 name: myapp-exec47spec:48 template:49 spec:50 containers:51 - name: app52 image: myapp:latest53 livenessProbe:54 exec:55 command:56 - sh57 - -c58 - "pgrep myapp || exit 1"59 initialDelaySeconds: 1560 periodSeconds: 20
1# Check liveness probe2kubectl describe pod my-pod | grep -A 10 "livenessProbe"34# Check restart count5kubectl get pod my-pod -o jsonpath='{.status.containerStatuses[0].restartCount}'67# View liveness failures8kubectl get events --field-selector reason=Unhealthy910# Check probe logs11kubectl logs my-pod --previous1213# Verify liveness endpoint14kubectl exec my-pod -- curl -s http://localhost:8080/healthz
Behavior:
Best Practices: