Q: What is an Admission Controller and how does Kubernetes use them?
An admission controller is a piece of API server code that intercepts a request after authentication and authorization but before the object is persisted to etcd, and can modify it, reject it, or both.
Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: An <strong>admission controller</strong> is a piece of API server code that intercepts a request after authentication and authorization but before the object is persisted to etcd, and can modify it, reject it, or both. Kubernetes uses admission controllers to enforce defaults and policy: injecting sidecars, applying quotas, enforcing Pod Security Standards and blocking non-compliant manifests. Interviewers ask this to see whether you understand the request lifecycle, the difference between mutating and validating stages, and the operational risk of a misconfigured webhook, which can block every deployment in a cluster. A strong answer also covers the newer in-process ValidatingAdmissionPolicy that reduces the need for webhooks.
Mental model: where an admission controller sits
Every write to the API server passes through a fixed pipeline, and admission is the last gate before persistence.
- Pipeline order: authentication, authorization (RBAC), mutating admission, object schema validation, validating admission, then the write to etcd. Reads (get, list, watch) are never admitted.
- Mutating: may change the object, for example adding a default StorageClass, injecting a sidecar container or setting resource requests. Mutating plugins run first so validation sees the final object.
- Validating: may only accept or reject. Examples are ResourceQuota, PodSecurity and your own policy checks. Any single rejection fails the whole request with a clear error message.
- Scope: admission acts on create, update, delete and connect (exec, port-forward) operations. It does not retroactively fix objects that already exist in etcd.
Hands-on: inspect built-in admission controllers
Built-in plugins compile into kube-apiserver and are toggled by flags, while dynamic ones are registered through API objects.
# See which plugins a kubeadm-style apiserver enables (flag may be absent = defaults)
kubectl -n kube-system get pod -l component=kube-apiserver -o yaml | grep -i admission
# List dynamic webhooks registered in the cluster
kubectl get mutatingwebhookconfigurations
kubectl get validatingwebhookconfigurations
# Server-side dry run triggers admission without persisting anything
kubectl apply -f deploy.yaml --dry-run=server
- Built-in examples:
NamespaceLifecycle,LimitRanger,ServiceAccount,ResourceQuota,DefaultStorageClass,NodeRestrictionandPodSecurity(stable since 1.25, replacing PodSecurityPolicy). - Configure: on self-managed control planes use
--enable-admission-pluginsand--disable-admission-pluginson the kube-apiserver manifest. Managed services (EKS, GKE, AKS) usually do not let you change these. - Dynamic:
MutatingWebhookConfigurationandValidatingWebhookConfigurationpoint the API server at an HTTPS service you run, which receives anAdmissionReviewand replies with allowed true or false plus optional JSON patches. - Defaults vary: the enabled-by-default list changes between minor versions, so confirm against your cluster instead of memorising it.
Hands-on: ValidatingAdmissionPolicy with CEL
Since Kubernetes 1.30 ValidatingAdmissionPolicy is GA, letting you express rules in CEL inside the API server with no webhook to run.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: require-replicas-limit
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: ["apps"]
apiVersions: ["v1"]
operations: ["CREATE","UPDATE"]
resources: ["deployments"]
validations:
- expression: "object.spec.replicas <= 10"
message: "replicas must be 10 or fewer"
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: require-replicas-limit-binding
spec:
policyName: require-replicas-limit
validationActions: ["Warn","Audit"] # switch to ["Deny"] once clean
- Policy: a
ValidatingAdmissionPolicyholdsmatchConstraintsand a list of CELvalidationswith messages. - Binding: a
ValidatingAdmissionPolicyBindingactivates the policy, selects namespaces and setsvalidationActionssuch asDeny,WarnorAudit. - Rollout tip: start with
WarnandAuditto see what would break, then switch toDeny. - Older clusters: on 1.28 and 1.29 the feature is beta and may need to be enabled; check your version before relying on it.
Verify what admission did to a request
When an apply is rejected or an object looks different from your manifest, confirm which stage acted.
- Read the error: rejections name the source, for example
admission webhook "x.example.com" denied the requestorexceeded quota. The name points at the exact webhook configuration. - Compare objects:
kubectl get pod my-pod -o yamlagainst your manifest shows mutations such as injected containers, default tolerations or added annotations. - Audit logs: API audit events and the apiserver metric
apiserver_admission_webhook_rejection_countshow which webhooks reject and how often. - Test safely:
--dry-run=serverruns the full admission chain, while--dry-run=clientskips it, so only the server variant is a valid policy test.
Failure modes and production practice
Webhooks sit on the critical path of every write, so their reliability directly becomes cluster reliability.
- failurePolicy:
Failblocks requests when the webhook is unreachable;Ignorelets them through. Security policies usually use Fail, but only with highly available webhook pods and a shorttimeoutSeconds. - Self-deadlock: a webhook that matches the pods or namespaces of its own deployment, or kube-system, can stop itself from restarting. Exclude them with
namespaceSelectororobjectSelector. - Side effects and ordering: declare
sideEffects: Nonewhere true so dry-run works, and remember mutating webhooks can be re-invoked viareinvocationPolicywhen another one changes the object. - Operate it: keep webhooks in GitOps, rotate serving certificates (cert-manager is common), alert on latency and rejection metrics, and prefer built-in plugins or CEL policies over custom webhooks when they can express the rule.
- An admission controller is API server logic that runs after authN/authZ and before etcd persistence, mutating or validating each write request.
- I verify behaviour with kubectl apply --dry-run=server, by diffing the live object against my manifest, and by checking webhook rejection metrics.
- I automate policy as code, using ValidatingAdmissionPolicy or a policy engine in GitOps, rolled out in Warn mode with HA webhooks and tight failurePolicy settings.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Confusing admission with RBAC RBAC decides who may act; admission inspects the object itself. A user with full RBAC rights can still be rejected by quota or policy.
- Letting a webhook match its own namespace If the webhook pods go down and the policy is Fail-closed, they cannot be recreated because their own creation request is blocked.
- Testing policy with client-side dry run --dry-run=client never contacts the API server, so no admission plugin or webhook runs and the test proves nothing.
- Using Fail with a single webhook replica and long timeout A slow or crashed replica stalls every matching write until the timeout, turning a policy tool into a cluster-wide outage.