Gatekeeper vs Kyverno: Kubernetes Policy Differences
OPA Gatekeeper vs Kyverno compared: Rego vs YAML and CEL, mutation, generation, image verification, audit, CI testing, and when to use built-in policies.
OPA Gatekeeper and Kyverno are both Kubernetes admission controllers for policy as code, but they differ in policy language, scope and workflow. Gatekeeper writes policies in Rego (with CEL support) through ConstraintTemplates and Constraints. Kyverno writes policies as Kubernetes YAML with CEL expressions, and adds built-in resource generation, cleanup and image signature verification.
This page compares the two tools side by side so you can pick one, or decide to use the built-in ValidatingAdmissionPolicy instead. How admission controllers fit in the Kubernetes API request path is explained in where admission controllers enforce security policies. Both belong to our Kubernetes architecture pillar.
Key takeaways
- Gatekeeper is a sub-project of Open Policy Agent (OPA), a CNCF graduated project. Policies use Rego, and Gatekeeper also supports CEL through its Kubernetes native validation engine.
- Kyverno is a CNCF project built only for Kubernetes. Its current policy types (ValidatingPolicy, MutatingPolicy, GeneratingPolicy, DeletingPolicy, ImageValidatingPolicy) use YAML and CEL; the older ClusterPolicy and cleanup policy kinds are marked deprecated in Kyverno's docs.
- Kyverno can generate resources (for example a default NetworkPolicy in every new namespace) and delete resources on a schedule. Gatekeeper does not generate resources.
- Gatekeeper fits teams that already use OPA and Rego outside Kubernetes, such as for Terraform or API authorization.
- Both audit existing resources and both have a CLI for testing in CI (
gatorfor Gatekeeper,kyvernofor Kyverno). - For simple validation, Kubernetes ValidatingAdmissionPolicy (CEL, GA since v1.30) may be enough without any third-party controller.
Side-by-side comparison
| Dimension | OPA Gatekeeper | Kyverno |
|---|---|---|
| Project | OPA sub-project; OPA is CNCF graduated | CNCF project |
| Scope | Kubernetes admission, built on general-purpose OPA | Kubernetes only |
| Policy language | Rego, plus CEL via the K8sNativeValidation engine | YAML with CEL expressions (older policies also used JMESPath and patterns) |
| Policy objects | ConstraintTemplate (logic) + Constraint (parameters, scope) | One policy resource per rule set |
| Validate | Yes | Yes |
| Mutate | Yes, with Assign, AssignMetadata, ModifySet, AssignImage | Yes, with patches or CEL in MutatingPolicy |
| Generate resources | No | Yes (GeneratingPolicy) |
| Delete or clean up resources | No | Yes (DeletingPolicy) |
| Image signature verification | Through external data providers | Built in (ImageValidatingPolicy, Sigstore Cosign and Notary) |
| Audit of existing resources | Audit controller writes violations to Constraint status | Background scans write PolicyReports |
| CLI for CI | gator test, gator verify | kyverno apply, kyverno test |
| Policy library | Gatekeeper library (ConstraintTemplates) | Kyverno policies library |
| Reuse outside Kubernetes | Rego works with OPA, Conftest and other OPA integrations | Kyverno also offers a JSON engine, but the project focus is Kubernetes |
Difference 1: how a policy is written
The most visible difference is the authoring model. Here is the same rule, "every Deployment must have an owner label", in both tools.
Gatekeeper: template plus constraint
The ConstraintTemplate holds the logic and creates a new CRD kind. The Constraint uses that kind to set parameters and scope.
apiVersion: templates.gatekeeper.sh/v1
kind: ConstraintTemplate
metadata:
name: k8srequiredlabels
spec:
crd:
spec:
names:
kind: K8sRequiredLabels
validation:
openAPIV3Schema:
type: object
properties:
labels:
type: array
items:
type: string
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package k8srequiredlabels
violation[{"msg": msg}] {
required := {label | label := input.parameters.labels[_]}
provided := {label | input.review.object.metadata.labels[label]}
missing := required - provided
count(missing) > 0
msg := sprintf("missing required labels: %v", [missing])
}
---
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequiredLabels
metadata:
name: deployments-must-have-owner
spec:
enforcementAction: deny
match:
kinds:
- apiGroups: ["apps"]
kinds: ["Deployment"]
parameters:
labels: ["owner"]
The split lets a platform team write templates once and let application teams create Constraints with different parameters. The cost is that someone has to know Rego.
Kyverno: one policy in YAML and CEL
apiVersion: policies.kyverno.io/v1
kind: ValidatingPolicy
metadata:
name: require-owner-label
spec:
validationActions: [Deny]
matchConstraints:
resourceRules:
- apiGroups: ["apps"]
apiVersions: ["v1"]
operations: ["CREATE", "UPDATE"]
resources: ["deployments"]
validations:
- expression: "has(object.metadata.labels) && 'owner' in object.metadata.labels"
message: "Deployments must have an owner label."
Kyverno's newer policy kinds mirror the structure of the Kubernetes ValidatingAdmissionPolicy API, so CEL skills carry over. Check the API version in the Kyverno documentation for the release you install, since policy kinds have moved between versions.
Difference 2: what each tool can do beyond validation
Both tools validate and mutate. Kyverno goes further:
- Generate: create or sync resources when something else is created, such as a default-deny NetworkPolicy, a ResourceQuota or an image pull Secret in each new namespace.
- Delete: remove resources that match conditions on a schedule, for example stale preview namespaces.
- Verify images: check Cosign or Notary signatures and attestations at admission and optionally pin tags to digests.
Gatekeeper keeps a narrower focus on validation, mutation and audit. Teams that use Gatekeeper usually handle generation with GitOps tooling or a namespace operator, and image verification with an external data provider such as Ratify.
Difference 3: audit and reporting
Gatekeeper's audit controller periodically checks existing resources against every Constraint and records violations in the Constraint's status field, with metrics exported for Prometheus. Kyverno runs background scans and writes results to PolicyReport and ClusterPolicyReport resources, a format from the Kubernetes Policy working group that dashboards such as Policy Reporter can read.
# Gatekeeper: violations for one constraint
kubectl get k8srequiredlabels deployments-must-have-owner -o yaml
# Kyverno: policy reports per namespace
kubectl get policyreports -A
Difference 4: testing in CI
Both tools let you test policies before they reach a cluster, which belongs in the same pipeline that applies your manifests.
# Gatekeeper: run a suite of templates, constraints and test objects
gator verify ./policy-tests/
# Kyverno: apply policies to manifests and run declared tests
kyverno apply ./policies/ --resource ./manifests/deployment.yaml
kyverno test ./policy-tests/
Teams that already use Conftest for Terraform or Dockerfiles can keep one Rego codebase across those checks and Gatekeeper. Our guide to OPA for DevOps governance covers that wider use of Rego.
Difference 5: rollout modes
| Goal | Gatekeeper | Kyverno |
|---|---|---|
| Block violations | enforcementAction: deny | validationActions: [Deny] |
| Allow but warn the user | enforcementAction: warn | validationActions: [Warn] |
| Record only | enforcementAction: dryrun | validationActions: [Audit] |
| Exclude namespaces | Config match exclusions, excludedNamespaces | Match conditions, PolicyExceptions |
The safe rollout pattern is the same for both: start in audit or dry run, fix existing violations, switch to warn, then deny.
Operational differences
- Failure policy. Both run as validating and mutating webhooks. If the controller is down and the webhook is set to fail closed, the API server rejects matching requests. Run several replicas, set PodDisruptionBudgets, and exclude system namespaces such as
kube-system. - Performance. Rego policies that query cached cluster data (Gatekeeper's sync config) can check things like unique Ingress hosts. Kyverno can look up other resources with API calls or context entries. Either can slow admission if policies are heavy; measure webhook latency with the API server's admission metrics.
- Skills. Rego is a declarative query language new to most Kubernetes engineers. Kyverno's YAML and CEL are closer to what they already write.
Handling exceptions
Every policy set needs a way to exempt specific workloads, such as a monitoring agent that needs host access. The two tools handle this differently.
- Gatekeeper handles exceptions through the Constraint's
matchblock (namespaces, label selectors,excludedNamespaces) and the cluster-wideConfigresource, which can exempt namespaces from particular processes such as audit or webhook checks. Because parameters live in Constraints, you can also write exception lists into the parameters and check them in Rego. - Kyverno has a dedicated
PolicyExceptionresource that names the policy and rule to skip and the resources it applies to. Exceptions can live in a restricted namespace so only the platform team can grant them, and each one is a reviewable object in Git.
Whichever tool you use, keep exceptions in version control with an owner and a reason, and review them regularly. An exception that nobody remembers adding is a gap in your policy.
Migrating between the two
Teams sometimes switch, usually from Gatekeeper to Kyverno to drop Rego, or from either tool to built-in CEL policies to remove a webhook. A low-risk path looks like this:
- List every enforced rule and the namespaces it applies to, including exceptions.
- Rewrite the rules in the new tool and test them in CI against the same manifests with
gatororkyverno test. - Install the new engine with all policies in audit or warn mode, and compare its reports with the old engine's violations for a few weeks.
- Switch the new policies to enforce one group at a time, then remove the matching rules from the old engine.
- Uninstall the old engine and confirm its webhook configurations are gone, so it cannot block requests after removal.
Where ValidatingAdmissionPolicy fits
Kubernetes has a built-in, in-process option: ValidatingAdmissionPolicy uses CEL and runs inside the API server, with no webhook. It became stable in v1.30. MutatingAdmissionPolicy, its mutation counterpart, is stable and enabled by default since v1.36 according to the Kubernetes docs. For straightforward checks (required labels, no hostPath, replica limits) these may remove the need for a third-party engine. Both Gatekeeper and Kyverno can work alongside them: Gatekeeper can generate ValidatingAdmissionPolicies from templates that use CEL, and Kyverno's newer policy kinds follow the same CEL model.
Which one should you choose?
| Your situation | Better fit |
|---|---|
| Already using OPA or Conftest elsewhere | Gatekeeper |
| Need one policy language across Kubernetes, Terraform and APIs | Gatekeeper (Rego) |
| Team knows YAML and CEL, not Rego | Kyverno |
| Need generated defaults per namespace | Kyverno |
| Need image signature checks with little setup | Kyverno |
| Only a handful of simple validation rules | ValidatingAdmissionPolicy |
| Strict separation of policy logic and parameters across teams | Gatekeeper templates and constraints |
Running both in the same cluster is possible but doubles the webhooks on every request and splits reporting, so most teams pick one. The admission policy layer is only one control; see Kubernetes security best practices and multi-tenant security practices for the rest. The broader case for policy as code in pipelines is in policy as code for DevOps governance.
Admission control and policy engines are part of the Certified Kubernetes Security Specialist exam. Our CKS training in Pune covers them with labs, in Kharadi or live online.
FAQ
What is the main difference between Gatekeeper and Kyverno?
Gatekeeper uses Rego (with CEL support) and separates logic in ConstraintTemplates from parameters in Constraints. Kyverno uses Kubernetes-style YAML with CEL and can also generate resources, delete resources and verify image signatures.
Is Kyverno easier than Gatekeeper?
For most Kubernetes engineers, yes, because policies look like other manifests and use CEL instead of Rego. Gatekeeper is easier for teams that already write Rego for OPA or Conftest.
Can Gatekeeper mutate resources?
Yes. Gatekeeper supports mutation through Assign, AssignMetadata, ModifySet and AssignImage resources. It does not generate new resources the way Kyverno does.
Can I use Gatekeeper and Kyverno together?
Technically yes, but each adds webhooks to every matching API request and reports violations in different formats. Most teams standardize on one engine.
Do I still need Gatekeeper or Kyverno with ValidatingAdmissionPolicy?
For simple validation, ValidatingAdmissionPolicy (stable since v1.30) may be enough. You still need an engine for audit reports, resource generation, image verification, a policy library or complex data lookups.
How do I test policies before deploying them?
Use gator verify or gator test for Gatekeeper and kyverno apply or kyverno test for Kyverno in your CI pipeline, then roll out in audit or dry-run mode before enforcing.
Which is better for image signature verification?
Kyverno has built-in signature and attestation checks for Cosign and Notary. Gatekeeper relies on external data providers such as Ratify for the same job.
References
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0