2019-10-23 21:06:03 +00:00
# Require `livenessProbe` and `readinessProbe`
2019-11-11 05:18:17 +00:00
Liveness and readiness probes need to be configured to correctly manage a pods lifecycle during deployments, restarts, and upgrades.
2019-10-23 21:06:03 +00:00
2019-11-11 05:18:17 +00: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 recieve network traffic.
2019-10-23 21:06:03 +00:00
## Policy YAML
[require_probes.yaml ](best_practices/require_probes.yaml )
````yaml
apiVersion: kyverno.io/v1alpha1
kind: ClusterPolicy
metadata:
2019-11-11 05:18:17 +00:00
name: require-pod-probes
2019-10-23 21:06:03 +00:00
spec:
rules:
2019-11-11 05:18:17 +00:00
- name: validate-livenessProbe-readinessProbe
2019-10-23 21:06:03 +00:00
match:
resources:
kinds:
- Pod
validate:
message: "Liveness and readiness probes are required"
pattern:
spec:
containers:
- livenessProbe:
periodSeconds: ">0"
readinessProbe:
periodSeconds: ">0"
````