Skip to content
LF Cert Trainer

Lesson 40 · Section 3: Scheduling

Lesson 40: Admission controllers: the last gate before etcd

What admission controllers are and why RBAC is not enough, the two phases every write passes through, the built-in plugins that shape your Pods, and how to list, enable and disable plugins on a kubeadm cluster. · 20 min read · 4 min video

1/9Admission controllers
0:00 / 3:34

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why admission controllers exist

Lesson 10 followed a request through the API server: authentication, authorization, admission, storage. The first two look at who is asking and what action they want. RBAC can say "jane may create Pods in the namespace shop", and that is all it can say. It never opens the Pod.

A real cluster needs rules about the content of objects:

  • Every Pod must have a ServiceAccount, and the ServiceAccount must exist.
  • A namespace may use at most 8 CPUs in total, however many Pods that is.
  • Containers without requests should get sensible defaults.
  • Pods in the namespace prod may not run privileged.
  • Nothing may be created in a namespace that is being deleted.

None of these is a yes or no about a user and a verb. They need a piece of code that reads the object, compares it with the state of the cluster, and then accepts it, changes it or refuses it. That code is an admission controller.

The name is misleading in one way. These are not controllers like the Deployment controller: they do not run in kube-controller-manager and they do not watch and reconcile. They are compiled into the kube-apiserver binary and run synchronously, inside the request. That is why they are also called admission plugins, and why the flags that manage them say plugins.

Where admission sits in a request

Where admission sits on the way to etcdadmissionadmittedkubectlcreate Pod webAuthenticationWho are you?AuthorizationMay you? (RBAC)Mutatingplugins may changeSchema checkvalid object?Validatingplugins: yes or noetcdobject stored
Where admission sits on the way to etcd. Authentication and authorization look at who is asking and what they want to do. Admission is the first step that looks inside the object itself, and it runs in two phases around the schema check.

Parts:

  • kubectl (create Pod web)
  • Authentication (Who are you?)
  • Authorization (May you? (RBAC))
  • Mutating (plugins may change)
  • Schema check (valid object?)
  • Validating (plugins: yes or no)
  • etcd (object stored)

Connections:

  • kubectl to Authentication
  • Authentication to Authorization
  • Authorization to Mutating: admission
  • Mutating to Schema check
  • Schema check to Validating
  • Validating to etcd: admitted
  1. Authentication works out who you are.
  2. Authorization (RBAC) decides whether you may make this request at all.
  3. Mutating admission runs. Plugins of this kind may change the object: add defaults, inject volumes, set fields you left out.
  4. The API server checks the object, as it now stands, against its schema.
  5. Validating admission runs. Plugins of this kind cannot change anything. Each one only answers yes or no.
  6. The object is written to etcd.

Three rules follow from this picture:

  • One no is enough. If any plugin in either phase rejects the request, the whole request fails at once and nothing is stored.
  • Mutating runs before validating, so the validators judge the final object, including everything the mutators added. A Pod that had no requests can still be refused by a quota, because LimitRanger gave it requests first.
  • Only writes are admitted. Admission sees requests that create, update, delete or connect (exec, attach, port-forward). Reads such as get, list and watch never reach it. Admission can stop you from creating a Pod; it cannot hide one from you.

A plugin is not limited to one phase. Several built-in plugins, such as LimitRanger and ServiceAccount, are both: they change the object in the first phase and check it again in the second.

The plugins you already use

What the built-in plugins do to a plain PodMutatingchangedyesyesYour Podname and image onlyServiceAccountdefault + tokenLimitRangerdefault requestsTolerationsnot-ready for 300sResourceQuotaroom in the quota?PodSecurityallowed here?Stored Podfields filled in
What the built-in plugins do to a plain Pod. You send a Pod with a name and an image. Mutating plugins fill in what is missing, and validating plugins can still refuse the result.

Parts:

  • Your Pod (name and image only)
  • ServiceAccount (default + token), in Mutating
  • LimitRanger (default requests), in Mutating
  • Tolerations (not-ready for 300s), in Mutating
  • ResourceQuota (room in the quota?)
  • PodSecurity (allowed here?)
  • Stored Pod (fields filled in)

Connections:

  • Your Pod to ServiceAccount
  • Your Pod to LimitRanger
  • Your Pod to Tolerations
  • LimitRanger to Stored Pod: changed
  • ResourceQuota to Stored Pod: yes
  • PodSecurity to Stored Pod: yes

Send the smallest possible Pod, then read back what was stored:

kubectl run web --image=nginx:1.29-alpine
kubectl get pod web -o yaml

The stored Pod has serviceAccountName: default, a kube-api-access-… volume mounted in the container, two tolerations with tolerationSeconds: 300, and a priority: 0. You wrote none of it. Mutating admission plugins did, and this is why the admission step belongs in a section about scheduling: several fields the scheduler and the kubelet later act on are put there by admission.

The built-in plugins worth knowing for the exam:

PluginPhaseWhat it doesDefault
NamespaceLifecycleValidatingRejects objects in a namespace that does not exist or is being deleted; protects default, kube-system and kube-public from deletionOn
ServiceAccountBothSets serviceAccountName: default when empty, rejects the Pod if the ServiceAccount does not exist, adds the token volume and image pull secretsOn
LimitRangerBothApplies the namespace's LimitRange: fills in default requests and limits, rejects Pods outside the minimum and maximumOn
ResourceQuotaValidatingRejects an object that would push the namespace over its ResourceQuotaOn
PodSecurityValidatingEnforces the Pod Security Standards chosen by namespace labels (pod-security.kubernetes.io/enforce)On
PriorityBothTurns priorityClassName into the numeric priority, and rejects a class that does not existOn
DefaultTolerationSecondsMutatingAdds tolerations for node.kubernetes.io/not-ready and unreachable with 300 seconds, so Pods survive a short node outageOn
TaintNodesByConditionMutatingTaints new Nodes as not-ready and NoSchedule until they report readyOn
DefaultStorageClassMutatingGives a PersistentVolumeClaim without a class the default StorageClassOn
DefaultIngressClassMutatingGives an Ingress without a class the default IngressClassOn
MutatingAdmissionWebhook, ValidatingAdmissionWebhookOne eachCall out to webhooks that you register (next lesson)On
ValidatingAdmissionPolicy, MutatingAdmissionPolicyOne eachEvaluate policies written as objects in the cluster, without a webhookOn
NodeRestrictionValidatingLimits each kubelet to its own Node object and the Pods bound to itOff, kubeadm turns it on
NamespaceAutoProvisionMutatingCreates the namespace when a request names one that does not existOff
NamespaceExistsValidatingRejects requests in a namespace that does not exist (already covered by NamespaceLifecycle)Off
AlwaysPullImagesBothForces imagePullPolicy: Always on every Pod, so a cached private image cannot be used without credentialsOff
PodNodeSelectorValidatingForces or limits the node selector of Pods per namespace, through a namespace annotationOff
AlwaysAdmit, AlwaysDenyValidatingAdmit or reject everything; deprecated, only of historical interestOff

In Kubernetes 1.37 about twenty plugins are on by default. The exact list changes a little from release to release, so ask your own cluster rather than memorising it (the next section shows how).

Under the hood · Why a rejected request can still leave a trace

An admission plugin does not know whether the plugins after it will accept the request. ResourceQuota has to count the new Pod against the quota when it sees it, and a later plugin may still say no. The quota usage is then briefly too high and is corrected by a controller that recalculates it. This is why the docs warn that plugins with side effects need a reconciliation process, and why quota usage can lag for a moment after a failed create.

The same reasoning explains --dry-run=server: the request goes through authentication, authorization and the full admission chain, and stops just before etcd. Plugins and webhooks are told it is a dry run so they skip their side effects.

Finding out which plugins are active

There is no API object that lists the active admission plugins, and kubectl has no command for it. The set is decided by two flags on kube-apiserver, on top of defaults that are compiled into the binary.

Which plugins run on a kubeadm clustereditrecreateplusminusactive setManifestkube-apiserver.yamlkubeletsees the file changekube-apiserverrestartsDefault setabout 20 pluginsEnable flagadds to the setDisable flagremoves defaults
Which plugins run on a kubeadm cluster. The set is built in three steps: the defaults compiled into kube-apiserver, plus what the enable flag adds, minus what the disable flag removes. Both flags live in the static Pod manifest.

Parts:

  • Manifest (kube-apiserver.yaml)
  • kubelet (sees the file change)
  • kube-apiserver (restarts)
  • Default set (about 20 plugins)
  • Enable flag (adds to the set)
  • Disable flag (removes defaults)

Connections:

  • Manifest to kubelet: edit
  • kubelet to kube-apiserver: recreate
  • Default set to Enable flag: plus
  • Enable flag to Disable flag: minus
  • Disable flag to kube-apiserver: active set
FlagMeaning
--enable-admission-plugins=A,BTurn on these plugins in addition to the defaults
--disable-admission-plugins=CTurn off these plugins although they are defaults
--admission-control-config-file=/pathA file with settings for individual plugins (for example exemptions for PodSecurity)

On a kubeadm cluster the flags are in the static Pod manifest:

sudo grep admission /etc/kubernetes/manifests/kube-apiserver.yaml
    - --enable-admission-plugins=NodeRestriction

That line shows only what was added. The defaults are not written anywhere in the manifest. To see them, ask the binary for its help text. The API server image contains the binary, so you can run it with kubectl exec:

kubectl -n kube-system exec kube-apiserver-controlplane -- kube-apiserver -h | grep enable-admission-plugins

The description of the flag names the default plugins in brackets and then lists every plugin that exists. The active set is: defaults, plus the enable flag, minus the disable flag.

On a cluster where the API server is a systemd service, read the unit file or the running process instead:

ps -ef | grep kube-apiserver | tr ' ' '\n' | grep admission

Using it

Example · Enable a plugin: create namespaces on demand

A task says: "Make the cluster create a namespace automatically when a Pod is created in a namespace that does not exist." First see the current behaviour:

kubectl run web --image=nginx:1.29-alpine -n blue
Error from server (NotFound): namespaces "blue" not found

That refusal comes from NamespaceLifecycle. The plugin that creates namespaces is NamespaceAutoProvision, and it is off by default. On the control plane node, back up the manifest outside the manifests folder and add the name to the existing flag:

ssh controlplane
sudo cp /etc/kubernetes/manifests/kube-apiserver.yaml /tmp/kube-apiserver.yaml.bak
sudo vi /etc/kubernetes/manifests/kube-apiserver.yaml
    - --enable-admission-plugins=NodeRestriction,NamespaceAutoProvision

Save. The kubelet notices the change and recreates the API server, which takes up to a minute. During that time kubectl answers connection refused; that is expected. Watch it come back, then try again:

sudo crictl ps --name kube-apiserver          # wait for a new container that stays Running
kubectl run web --image=nginx:1.29-alpine -n blue
kubectl get namespace blue
pod/web created
NAME   STATUS   AGE
blue   Active   9s

NamespaceAutoProvision is a mutating plugin, so it runs first and creates the namespace; by the time NamespaceLifecycle validates the request, the namespace exists.

Example · Disable a default plugin

A task says: "Disable the DefaultStorageClass admission plugin." It is a default, so it does not appear in the manifest and there is nothing to delete. Add the disable flag as a new line in the command list:

    - --enable-admission-plugins=NodeRestriction
    - --disable-admission-plugins=DefaultStorageClass

After the API server has restarted, confirm that the running process carries the flag:

kubectl -n kube-system get pod kube-apiserver-controlplane -o yaml | grep admission-plugins
ps -ef | grep kube-apiserver | tr ' ' '\n' | grep admission        # on the control plane node

A PersistentVolumeClaim created without storageClassName now stays without a class, and stays Pending unless a matching PersistentVolume exists.

Example · Tell which gate refused a request

Three errors that look alike come from three different places. Read the wording:

Error from server (Forbidden): pods is forbidden: User "jane" cannot create resource "pods"
in API group "" in the namespace "shop"

A user, a verb and a resource: this is RBAC. Fix a Role or a RoleBinding.

Error from server (Forbidden): pods "web" is forbidden: exceeded quota: compute, requested: cpu=2,
used: cpu=7, limited: cpu=8

Also Forbidden, but the reason is about the object: this is admission (ResourceQuota). Lower the request or raise the quota.

Error from server (Forbidden): pods "web" is forbidden: error looking up service account
shop/builder: serviceaccount "builder" not found

Admission again (ServiceAccount). Create the ServiceAccount or fix the name in the Pod.

Other typical admission messages are violates PodSecurity "restricted:latest", maximum cpu usage per Container is 1, but limit is 2 (LimitRanger) and no PriorityClass with name high found (Priority). To test a manifest against all of them without creating anything:

kubectl apply -f pod.yaml --dry-run=server

Example · Repair an API server that will not start after your edit

You saved the manifest and kubectl keeps answering connection refused after two minutes. The API server is crashing, so ask the container runtime on the control plane node:

sudo crictl ps -a --name kube-apiserver
sudo crictl logs <container-id>
Error: enable-admission-plugins plugin "NamespaceAutoProvison" is unknown

The name is misspelled. Plugin names are case sensitive and must match exactly. Fix the line, save, and wait for the container to come back. If no container appears at all, the manifest itself cannot be parsed (usually broken indentation); sudo journalctl -u kubelet --since "2 min ago" | grep -i apiserver shows the reason, and the backup in /tmp gets you back to a working state.

Tricks

Common mistakes

  • Looking for admission plugins with kubectl get. The built-in plugins are not API objects. They are flags on kube-apiserver. Only webhooks and admission policies are objects (next lesson).
  • Reading the manifest and concluding only NodeRestriction is active. About twenty defaults run without being named anywhere.
  • Removing a name from the enable flag to turn off a default. Defaults are on whether you list them or not. Use --disable-admission-plugins.
  • Blaming RBAC for every Forbidden. RBAC names a user, a verb and a resource. Anything else after is forbidden: comes from admission.
  • Expecting admission to act on existing objects. Plugins only see requests. Enabling AlwaysPullImages or a stricter Pod Security level does not change or remove Pods that are already running.
  • Waiting for a rejected Pod to show up as Pending. A rejected request stores nothing. Pending is a scheduling state, and scheduling only starts after admission.

Recap

  • Admission controllers are plugins inside kube-apiserver that run after authorization and before etcd, on writes only.
  • Mutating plugins run first and may change the object; validating plugins run last and may only reject it. One rejection fails the request.
  • You already rely on them: ServiceAccount, LimitRanger, ResourceQuota, DefaultTolerationSeconds, Priority, NamespaceLifecycle, PodSecurity.
  • The active set is the built-in defaults, plus --enable-admission-plugins, minus --disable-admission-plugins, set in /etc/kubernetes/manifests/kube-apiserver.yaml on kubeadm.
  • List the defaults with kube-apiserver -h | grep enable-admission-plugins, and debug a failed restart with crictl logs.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Practise: try it on a real cluster

A hands-on lab for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Switch one admission plugin on and another off in the API server of a kubeadm cluster, without losing the plugins that were already active.

    Build · Level 3 · challenge · target 18 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.