Admission controllers are HTTP callbacks that receive admission requests and then perform actions on them. They act as extensions to the Kubernetes admission controller webhook process, intercepting requests to the API server before objects are persisted. By leveraging k8s webhooks, you can enforce security policies, ensure adherence to certain practices, and automate the validation or configuration of objects in your cluster.
There are two types of admission controllers:
These are invoked first and can modify objects sent to the API server to enforce custom defaults. A Kubernetes mutating admission webhook (part of the broader Kubernetes mutating admission controller) is crucial for tasks like injecting sidecar containers or applying default resource values.
These run after all object modifications are complete and after the API server’s own validation. A Kubernetes validating webhook can then reject requests that fail certain policies.
It is important to note that validating admission controllers should be used to guarantee that they see the final state of the object in order to enforce policy, since objects can be modified after being processed by mutating webhooks.
A Kubernetes webhook admission controller is configured dynamically using MutatingWebhookConfiguration
or ValidatingWebhookConfiguration
API objects. Each configuration can contain one or more webhooks, each with a unique name.
A webhook configuration typically includes:
CREATE,
UPDATE,
DELETE,
CONNECT
, or *
), API groups, API versions, resources, and scope (Cluster
, Namespaced
, or *
) that the webhook should intercept.Exact
or Equivalent
matching. It is generally recommended to use Equivalent
to ensure that webhooks continue to intercept the resources they expect when upgrades enable new versions of the resource in the API server.clientConfig
stanza, which can use a URL or a service reference. If the webhook is running within the cluster, use a service reference instead of a URL.dryRun: true
admission requests are handled. The sideEffects
field should be set to None
if a webhook doesn't have any side effect.timeoutSeconds
field allows configuring how long the API server should wait for a webhook to respond before treating the call as a failure. The timeout value must be between 1 and 30 seconds.reinvocationPolicy
to control whether they are reinvoked if the object is modified by other admission plugins after the initial webhook call.failurePolicy
field defines how unrecognized errors and timeout errors from the admission webhook are handled, with options to Ignore
or Fail
..webhooks[].matchPolicy
to Equivalent
.namespaceSelector
.kube-system
namespace may cause the control plane components to stop functioning or introduce unknown behavior. kube-system
namespace from being intercepted using a namespaceSelector
..webhooks[].sideEffects
field to None
if a webhook doesn't have any side effects. If side effects are required, they must be suppressed when processing an AdmissionReview
object with dryRun
set to true
.failurePolicy
to Fail
. Otherwise, Ignore
may be more appropriate.Debugging failing k8s admission webhook logic can be challenging. Here are some methods:
mutation.webhook.admission.k8s.io/round_{round idx}_index_{order idx}
indicating invocation and mutation.patch.webhook.admission.k8s.io/round_{round idx}_index_{order idx}
indicating the actual patch applied./metrics
endpoint, which can be used for monitoring and diagnosing API server status. apiserver_admission_webhook_rejection_count
: This metric records admission webhook rejections, labeled by webhook name, operation type, admission webhook type, error type, and rejection code.Webhooks respond with 200 OK
and provide an AdmissionReview
object containing:
true
or false
to allow or reject.299
to the requesting client.Admission controllers—whether a Kubernetes mutating admission webhook, Kubernetes validating webhook, or any other k8s webhook mechanism—are powerful tools for extending Kubernetes admission controller processes. Even with robust webhook configurations, detecting misconfigurations in a live environment or during upgrades can get complicated—often requiring specialized tooling and automated checks.
If you prefer not to build and maintain all that yourself, Chkk Risk Ledger can help you spot issues in your running clusters, catching them before they escalate. And when it’s time to upgrade, Chkk Upgrade Copilot identifies configurations that might block or complicate the process. By combining best practices for admission webhooks with these specialized tools, you ensure that application teams fix issues at the right time, maintaining the balance between availability and agility that Kubernetes requires.