2019-10-23 14:06:03 -07:00
# Require `livenessProbe` and `readinessProbe`
2019-11-10 21:18:17 -08:00
Liveness and readiness probes need to be configured to correctly manage a pods lifecycle during deployments, restarts, and upgrades.
2019-10-23 14:06:03 -07:00
2019-11-12 17:40:54 -08:00
For each pod, a periodic `livenessProbe` is performed by the kubelet to determine if the pod's containers are running or need to be restarted. A `readinessProbe` is used by services and deployments to determine if the pod is ready to receive network traffic.
2019-10-23 14:06:03 -07:00
## Policy YAML
[require_probes.yaml ](best_practices/require_probes.yaml )
````yaml
2019-11-13 13:56:20 -08:00
apiVersion: kyverno.io/v1
2019-10-23 14:06:03 -07:00
kind: ClusterPolicy
metadata:
2019-11-10 21:18:17 -08:00
name: require-pod-probes
2019-10-23 14:06:03 -07:00
spec:
2020-08-19 14:04:58 -07:00
validationFailureAction: audit
2019-10-23 14:06:03 -07:00
rules:
2019-11-10 21:18:17 -08:00
- name: validate-livenessProbe-readinessProbe
2019-10-23 14:06:03 -07:00
match:
resources:
kinds:
- Pod
validate:
message: "Liveness and readiness probes are required"
pattern:
spec:
containers:
- livenessProbe:
periodSeconds: ">0"
readinessProbe:
periodSeconds: ">0"
````