Sub topic 17
Choosing between Kyverno and Gatekeeper
This chapter assumes you have read the earlier chapters. You should know how admission webhooks work, how Kyverno policies and Gatekeeper templates and constraints are written, and how enforcement, audit, exceptions and testing work in each engine. Here you compare the two engines and pick one for a given team.
What differs
Both engines sit behind a validating admission webhook, and both can audit existing resources. The differences are in how you write policy and which features come built in.
| Dimension | Kyverno | Gatekeeper |
|---|---|---|
| Policy language | Kubernetes YAML with patterns, JMESPath and CEL | Rego, in a ConstraintTemplate |
| Policy objects | ClusterPolicy or Policy | ConstraintTemplate plus Constraint |
| Mutation | Mature, with `patchStrategicMerge` and JSON patches | Separate mutation CRDs such as Assign and AssignMetadata |
| Generate resources | Built in (`generate` rules) | Not supported |
| Image signature checks | Built in (`verifyImages`) | Not built in. Needs external data or a custom setup |
| Reuse | Parameters are written into each policy | One template can back many constraints |
| Policy reach | Kubernetes resources, plus a CLI for testing | Rego is also used with OPA outside Kubernetes |
Decision criteria
Pick Kyverno when:
- Your team already writes Kubernetes YAML and does not want to learn a new language.
- You need mutation, generation of default resources (such as a NetworkPolicy per namespace) or image verification in one tool.
- You want quick onboarding for platform engineers who are not policy specialists.
Pick Gatekeeper when:
- You need logic that patterns cannot express, such as set operations, cross-field checks or loops.
- You already use OPA or Rego elsewhere, for example in CI or API authorization, and want one policy language.
- You want a small set of reviewed templates that many teams reuse through constraints with different parameters.
Trade-offs to weigh
- Learning cost. Rego takes time to learn and to debug. Kyverno patterns are easier to read but can get awkward for complex conditions.
- Separation of duties. Gatekeeper splits authors (who write templates) from users (who write constraints). Kyverno has no equivalent split, so you rely on RBAC and review.
- Failure modes. Both are webhooks. An unavailable webhook with
failurePolicy: Failcan block deployments in either engine. Plan replicas, exclusions and monitoring for whichever you choose. - Migration. Policies do not convert automatically. Changing engines means rewriting rules and retesting them.
A quick way to decide
If both fit, run a short pilot. Write your three most important policies in each engine, test them, and compare how readable they are and how long they take to review.
Exercise
Your platform team has no Rego experience. You must require a team label on Pods, add a default label to Pods that lack it, and create a default NetworkPolicy in every new namespace. Which engine fits best, and why?
Show answer
Kyverno. It covers validate, mutate and generate rules in one tool, using YAML the team already knows. Gatekeeper has no generate feature, and writing the label check would require learning Rego.