Opscraft
Open Policy Agent · Lesson 4 of 9 · 3 min read

Kyverno and Kubernetes' built-in policy options

Kyverno

A Kubernetes-native policy engine (CNCF) where policies are YAML, not Rego:

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata: { name: require-owner-label }
spec:
  validationFailureAction: Audit         # or Enforce
  background: true                       # also scan existing resources
  rules:
  - name: check-owner
    match:
      any:
      - resources: { kinds: [Namespace] }
    validate:
      message: "Namespaces need an 'owner' label."
      pattern:
        metadata:
          labels:
            owner: "?*"

Kyverno can validate, mutate, generate resources (e.g. create a default NetworkPolicy and ResourceQuota in every new namespace), verify image signatures (cosign/Notary), and clean up resources.

Gatekeeper vs Kyverno

Gatekeeper (OPA) Kyverno
Policy language Rego YAML (patterns, JMESPath, CEL)
Learning curve Steeper Gentle for Kubernetes engineers
Expressiveness Very high; complex logic, reusable High for K8s; complex logic gets awkward
Reuse outside Kubernetes Yes — same Rego in CI (conftest), Envoy, Terraform Kubernetes-focused (kyverno CLI for CI)
Mutation / generation Mutation yes; generation no Both
Image verification Via external data providers Built-in

A balanced answer: Kyverno is often faster to adopt for a Kubernetes-only team; Gatekeeper/OPA wins when policies are complex or you want one policy language across Kubernetes, CI and APIs.

Enlarge diagramGatekeeper (OPA)KyvernoRego: powerful, steeperSame rules in CI, Envoy, TerraformMutation, no generationBest for complex logicPolicies are YAMLFast for Kubernetes teamsMutate, generate, verify imagesKubernetes-focused
Figure 1. Gatekeeper or Kyverno.
Swipe sideways to see all of it, or tap to open it full screen.

Built-in options

  • Pod Security Admission (PSA) — enforces the Pod Security Standards (privileged, baseline, restricted) per namespace via labels. No custom rules, but zero extra components — use it as a baseline.
  • ValidatingAdmissionPolicy — built-in (GA in 1.30) validation with CEL expressions, evaluated inside the API server: no webhook latency or availability risk.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata: { name: replicas-limit }
spec:
  matchConstraints:
    resourceRules:
    - apiGroups: ["apps"]
      apiVersions: ["v1"]
      operations: ["CREATE", "UPDATE"]
      resources: ["deployments"]
  validations:
  - expression: "object.spec.replicas <= 20"
    message: "replicas must be <= 20"

(Bound to resources with a ValidatingAdmissionPolicyBinding.) Expect the ecosystem to move simple policies toward CEL, keeping OPA/Kyverno for richer needs.