How do I enforce policy-as-code for Probes (liveness/readiness/startup) using OPA and Conftest?

Enforcing policy-as-code for Kubernetes probes (liveness, readiness, and startup) can be effectively achieved using Open Policy Agent (OPA) and Conftest. By defining the appropriate policies, you can ensure that your Kubernetes configurations adhere to best practices.

Example Policy for Probes

package k8s_probes default allow = false # Allow if liveness and readiness probes are configured correctly allow { input.kind == "Pod" some i probe := input.spec.containers[i].livenessProbe probe != null } allow { input.kind == "Pod" some i probe := input.spec.containers[i].readinessProbe probe != null } # Optionally customize the rules further for startupProbes

keywords: policy-as-code OPA Conftest Kubernetes probes liveness readiness startup