1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/samples/RequirePodProbes.md

43 lines
1.7 KiB
Markdown
Raw Normal View History

2019-10-23 14:06:03 -07:00
# Require `livenessProbe` and `readinessProbe`
2020-11-11 15:55:02 -05:00
Liveness and readiness probes need to be configured to correctly manage a pod's 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
In this sample policy, a validation rule checks to ensure that all Pods have both a liveness and a readiness probe defined by looking at the `periodSeconds` field. By using the annotation `pod-policies.kyverno.io/autogen-controllers`, it modifies the default behavior and ensures that only Pods originating from DaemonSet, Deployment, and StatefulSet objects are validated.
## More Information
* [Kyverno Auto-Gen Rules for Pod Controllers](https://kyverno.io/docs/writing-policies/autogen/)
* [Configure Liveness, Readiness and Startup Probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)
2020-11-11 15:55:02 -05:00
## Policy YAML
2019-10-23 14:06:03 -07:00
[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
annotations:
pod-policies.kyverno.io/autogen-controllers: DaemonSet,Deployment,StatefulSet
2019-10-23 14:06:03 -07:00
spec:
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:
2020-11-11 15:55:02 -05:00
periodSeconds: ">0"
2019-10-23 14:06:03 -07:00
readinessProbe:
periodSeconds: ">0"
```