A Kubernetes admission controller checks or modifies matching write requests after authentication and authorization, before the object is stored. Native CEL policies can handle custom validation; webhooks and engines such as Kyverno or Gatekeeper add other capabilities. Read requests do not pass through admission.
Once you understand this flow, it also becomes clear how tools such as Gatekeeper or Kyverno enforce their own policies without touching a line of Kubernetes source code.
I run Kubernetes clusters in production and wrote the Kubernetes Practical Guide published by Rheinwerk Computing, with its own chapter on governance and security. You can find all my Kubernetes articles collected on the Kubernetes page.
What a Kubernetes admission controller checks
A write request to the Kubernetes API server passes through several stages before an object actually lands in the cluster. First, the API server figures out who is sending the request, usually via the certificate in your kubeconfig. Then it checks whether that user is even allowed to perform the action, which is handled by RBAC. How the permission model behind it is built is covered in Kubernetes RBAC: Roles and Permissions.
Only after that do admission controllers come into play, in two passes. In the first pass, mutating admission controllers are still allowed to change the manifest, for example adding a default label or setting a CPU limit. Kubernetes then checks whether the changed manifest is formally valid. In the second pass, validating admission controllers may only accept or reject the result, they cannot change anything anymore. Only once this step passes does the object land in etcd and become active in the cluster.
Kubernetes already ships with a number of built-in admission controllers, for example for default storage classes or for resource limits per namespace. Which of them are active is decided by the API server configuration, which is up to your cluster admins. A full overview is available in the Kubernetes documentation on admission controllers.
Kubernetes admission controller webhook: hooking in your own rules
Built-in admission controllers cover many standard cases, but custom rules, such as which image registries are allowed, need more flexibility. That is what two special admission controllers are for, and neither contains any logic of its own: they forward the request to an external service instead. These are the MutatingAdmissionWebhook and the ValidatingAdmissionWebhook.
A Kubernetes admission controller webhook is technically nothing more than an HTTPS endpoint, one you can run yourself or one shipped by a ready-made tool. On every matching request, Kubernetes sends the manifest to that endpoint and waits for an answer: allowed, rejected, or, in the case of the mutating webhook, a changed manifest. This exact mechanism is what the two best known policy tools in the Kubernetes world, Gatekeeper and Kyverno, build on. For simple checks there have also been Validating Admission Policies for a few releases now: rules written in the Common Expression Language that the API server evaluates itself, with no webhook service of your own.
Native CEL policy, Kyverno or Gatekeeper?
For straightforward validation, consider native ValidatingAdmissionPolicy first. It has been stable since Kubernetes 1.30: the API server evaluates CEL, while a binding defines scope and response. No separate webhook service is required. Your cluster must expose the API and admission controller, and you need permission to manage these resources.
Kyverno supports CEL as well as YAML patterns. Gatekeeper uses ConstraintTemplate and Constraint for validation; Rego is established, and current versions also support CEL code. Mutation is configured separately. “YAML versus Rego” alone is therefore an incomplete selection rule. Choose by required capability, existing policies and what your team can operate.
Documentation example: check a registry with native CEL
Documentation-based, not a locally executed cluster test. Sources checked: 31 October 2026. This example adapts the official VAP documentation. It requires Kubernetes 1.30 or later, the available admissionregistration.k8s.io/v1 API, an enabled ValidatingAdmissionPolicy controller and suitable administrator permissions. Check it against your exact version in an isolated test cluster before adopting it.
The binding applies only to policy-demo. It checks regular, init and ephemeral containers, including updates to the ephemeral-container subresource. The registry and object names are placeholders.
apiVersion: v1
kind: Namespace
metadata:
name: policy-demo
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: trusted-registry.example.com
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: [""]
apiVersions: ["v1"]
operations: ["CREATE", "UPDATE"]
resources: ["pods", "pods/ephemeralcontainers"]
variables:
- name: allContainers
expression: >-
object.spec.containers +
(has(object.spec.initContainers) ? object.spec.initContainers : []) +
(has(object.spec.ephemeralContainers) ? object.spec.ephemeralContainers : [])
validations:
- expression: >-
variables.allContainers.all(c,
c.image.startsWith('registry.example.internal/'))
message: "Images must use registry.example.internal/"
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: trusted-registry-demo
spec:
policyName: trusted-registry.example.com
validationActions: [Warn, Audit]
matchResources:
namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: policy-demo
Verification plan, not recorded test output:
Successful admission does not mean an image exists or can be pulled. The trailing slash prevents a similarly prefixed hostname from matching. This checks no signatures, digests or vulnerabilities. Other admission rules can still deny the request. For a Deployment, the generated Pod is checked, not the Deployment manifest itself.
Warn notifies the client; Audit adds a violation to configured Kubernetes audit events. It creates neither a Kyverno/Gatekeeper policy report nor a scan of existing Pods. Do not combine Deny and Warn. failurePolicy: Fail controls evaluation failures; the binding actions determine their response. Verify negative cases, scope and a rollback to Warn, Audit before enabling Deny, Audit.
Resource quotas and limit ranges: policy without a webhook
Not every rule needs a webhook. Two built-in objects solve a similar task without installing a policy engine: ResourceQuota and LimitRange. A ResourceQuota limits how many Pods, or how much CPU and memory, an entire namespace may request in total, which protects the cluster from one team claiming every resource. A LimitRange instead sets a minimum, maximum and default for a single Pod or container, independent of the namespace's quota.
Both objects complement Gatekeeper and Kyverno, they do not replace them. A ResourceQuota does not stop someone from pulling an image from the wrong registry, and pure validation does not set request defaults. Mutating policy rules can add values. One possible combination is LimitRange and ResourceQuota for resource limits, plus a suitable policy for other requirements.
Observe before blocking
Start with a narrow scope and warnings or audit reports. Native VAP evaluates matching new requests; an inventory of existing resources requires a separate scan or an engine with audit functionality. Check allowed and disallowed objects, init/ephemeral containers and updates to existing Pods. Verify where warnings and audit events arrive.
Enable denial only after those checks, with an owner and a rollback path. Admission does not retroactively change existing objects, but it can block later updates and replacement Pods for a Deployment. Include those operational cases in acceptance.
Frequently asked questions
What is the difference between a mutating and a validating admission webhook?
A mutating admission webhook can still change a manifest, for example by adding a label. A validating admission webhook can only accept or reject a manifest. Kubernetes always calls all mutating webhooks first and only then the validating webhooks, so validation sees the final, already changed manifest.
Do I need Gatekeeper or Kyverno if I already use RBAC?
Not necessarily: native CEL policies can cover field checks. RBAC decides who may perform an action, such as creating a Pod. A policy engine like Gatekeeper or Kyverno decides what that Pod is allowed to look like, such as which registry or which security context is permitted. The two layers complement each other, neither replaces the other.
Do resource quotas replace a policy engine?
No. ResourceQuota and LimitRange set limits for resources such as CPU and memory per namespace or Pod, and nothing beyond that. Rules about images, labels or security settings need additional validation, such as native CEL policies, Gatekeeper or Kyverno.
How do I test a new Kyverno policy without blocking the cluster?
For a current Kyverno ClusterPolicy, start with spec.rules[].validate.failureAction: Audit. Review policy reports with a suitable background scan before enabling denial. The older spec.validationFailureAction field has been deprecated since Kyverno 1.13; other policy types use different fields. See Kyverno policy settings.
Where to go next
Admission controllers and policies are the third building block, alongside RBAC and Pod Security Standards, for securing a Kubernetes cluster against unsafe manifests. How RBAC works in detail is covered in Kubernetes RBAC: Roles and Permissions, and the baseline settings for Pods in Kubernetes Pod Security Standards. If you want to build your own objects instead of relying on ready-made policy engines, the starting point is Kubernetes Operator and CRD Explained.
To get started, evaluate one native CEL rule with warnings in a test cluster. If you need additional capabilities, compare Kyverno and Gatekeeper using a concrete policy and its audit output.
In full detail with all examples, this is covered in chapter 7 of my Kubernetes Practical Guide (Rheinwerk Computing).