<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Iresh Ekanayaka</title>
    <description>The latest articles on DEV Community by Iresh Ekanayaka (@iresh).</description>
    <link>https://dev.to/iresh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3766011%2F1cffea2f-3edb-4038-8cb2-5f84d9ec13e7.jpg</url>
      <title>DEV Community: Iresh Ekanayaka</title>
      <link>https://dev.to/iresh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iresh"/>
    <language>en</language>
    <item>
      <title>Mutating vs Validating Webhooks in Kubernetes</title>
      <dc:creator>Iresh Ekanayaka</dc:creator>
      <pubDate>Thu, 12 Feb 2026 07:00:35 +0000</pubDate>
      <link>https://dev.to/iresh/kubernetes-admission-controllers-explained-355k</link>
      <guid>https://dev.to/iresh/kubernetes-admission-controllers-explained-355k</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7tacdh7hgwirouhzlq43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7tacdh7hgwirouhzlq43.png" alt="Admission Controller Phases" width="800" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Kubernetes is powerful - but with great power comes great “who deployed this to prod?”&lt;/p&gt;

&lt;p&gt;That’s where &lt;strong&gt;Admission Controllers&lt;/strong&gt; come in.&lt;/p&gt;

&lt;p&gt;They act like policy enforcement gates inside the Kubernetes API server. Before anything gets stored in the cluster, admission controllers can validate it, modify it, or completely reject it.&lt;/p&gt;

&lt;p&gt;Let’s break it down properly.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Are Admission Controllers?
&lt;/h2&gt;

&lt;p&gt;An &lt;strong&gt;Admission Controller&lt;/strong&gt; is code that intercepts requests to the Kubernetes API server &lt;strong&gt;after authentication and authorization&lt;/strong&gt;, but &lt;strong&gt;before the object is persisted in etcd&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In simpler terms:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;They’re middleware for the Kubernetes API.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; deployment.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The request flow looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Request → Authentication → Authorization → Mutating Admission → Schema Validation → Validating Admission → etcd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Admission controllers sit right in the middle of this pipeline.&lt;/p&gt;




&lt;h2&gt;
  
  
  Two Main Types of Admission Controllers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Mutating Admission Controllers
&lt;/h3&gt;

&lt;p&gt;These can &lt;strong&gt;modify&lt;/strong&gt; incoming requests before they are stored.&lt;/p&gt;

&lt;p&gt;Common examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding default labels&lt;/li&gt;
&lt;li&gt;Injecting sidecar containers (for example with Istio)&lt;/li&gt;
&lt;li&gt;Adding default resource limits&lt;/li&gt;
&lt;li&gt;Overriding missing fields&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mutating controllers run &lt;strong&gt;first&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;They take your original object and are allowed to change it.&lt;/p&gt;




&lt;h3&gt;
  
  
  Validating Admission Controllers
&lt;/h3&gt;

&lt;p&gt;These &lt;strong&gt;cannot modify&lt;/strong&gt; the request.&lt;/p&gt;

&lt;p&gt;They only decide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allow ✅&lt;/li&gt;
&lt;li&gt;Reject ❌&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Blocking privileged containers&lt;/li&gt;
&lt;li&gt;Enforcing image registry policies&lt;/li&gt;
&lt;li&gt;Validating required labels&lt;/li&gt;
&lt;li&gt;Enforcing naming standards&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Validating controllers run &lt;strong&gt;after mutation&lt;/strong&gt;, meaning they see the final version of the object.&lt;/p&gt;

&lt;p&gt;That ordering is important.&lt;/p&gt;




&lt;h2&gt;
  
  
  Static vs Dynamic Admission Controllers
&lt;/h2&gt;

&lt;p&gt;Admission controllers come in two forms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Static (Built-in)
&lt;/h3&gt;

&lt;p&gt;These ship with Kubernetes and are enabled via the API server flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;--enable-admission-plugins&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Common examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;NamespaceLifecycle&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;LimitRanger&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ResourceQuota&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ServiceAccount&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, &lt;code&gt;NamespaceLifecycle&lt;/code&gt; prevents you from creating new resources in a namespace that is being terminated.&lt;/p&gt;

&lt;p&gt;Many features people assume are “core Kubernetes behavior” are actually implemented using these built-in admission controllers.&lt;/p&gt;




&lt;h3&gt;
  
  
  Dynamic (Webhook-Based)
&lt;/h3&gt;

&lt;p&gt;These are far more flexible.&lt;/p&gt;

&lt;p&gt;They include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;MutatingAdmissionWebhook&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ValidatingAdmissionWebhook&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of embedding logic directly in the API server, Kubernetes calls an external HTTPS service (a webhook) and asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Is this request okay?”&lt;br&gt;
“Do you want to change anything?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This means you can implement custom logic in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go&lt;/li&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;li&gt;Node&lt;/li&gt;
&lt;li&gt;Any language capable of serving HTTPS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is where things get powerful.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Admission Controllers Matter
&lt;/h2&gt;

&lt;p&gt;In real-world clusters, most use cases fall into two categories: &lt;strong&gt;security&lt;/strong&gt; and &lt;strong&gt;governance&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Security
&lt;/h3&gt;

&lt;p&gt;Admission controllers can enforce a security baseline across your cluster.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Block containers running as root&lt;/li&gt;
&lt;li&gt;Allow images only from trusted registries&lt;/li&gt;
&lt;li&gt;Enforce read-only root filesystems&lt;/li&gt;
&lt;li&gt;Prevent &lt;code&gt;hostPath&lt;/code&gt; usage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, you can reject any deployment that includes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;securityContext&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;privileged&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That alone can prevent some serious security risks.&lt;/p&gt;




&lt;h3&gt;
  
  
  Governance &amp;amp; Compliance
&lt;/h3&gt;

&lt;p&gt;They also help enforce organizational standards:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Naming conventions&lt;/li&gt;
&lt;li&gt;Required labels&lt;/li&gt;
&lt;li&gt;Resource limits&lt;/li&gt;
&lt;li&gt;Replica restrictions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, you can enforce that every deployment must include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;production&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No label? No deploy.&lt;/p&gt;

&lt;p&gt;Simple. Effective.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real-World Example: Ingress Controllers
&lt;/h2&gt;

&lt;p&gt;When installing an ingress controller like F5 NGINX Ingress Controller, you’ll notice it creates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;MutatingWebhookConfiguration&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ValidatingWebhookConfiguration&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because Kubernetes doesn’t understand NGINX-specific configuration logic.&lt;/p&gt;

&lt;p&gt;The webhook:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validates ingress annotations&lt;/li&gt;
&lt;li&gt;Prevents invalid configurations&lt;/li&gt;
&lt;li&gt;Stops broken NGINX reloads&lt;/li&gt;
&lt;li&gt;Protects production traffic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without this layer, a bad Ingress definition could generate an invalid NGINX config and impact live traffic.&lt;/p&gt;

&lt;p&gt;That webhook is your safety net.&lt;/p&gt;




&lt;h2&gt;
  
  
  How Mutating and Validating Work Together
&lt;/h2&gt;

&lt;p&gt;Let’s say you create a Deployment like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;replicas&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s what might happen:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A mutating webhook changes replicas to &lt;code&gt;3&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A validating webhook checks that replicas are not greater than &lt;code&gt;5&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If valid → the object is stored in etcd&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This layered approach ensures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Defaults are applied&lt;/li&gt;
&lt;li&gt;Policies are enforced&lt;/li&gt;
&lt;li&gt;Broken configurations never reach the cluster state&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Enabling Admission Controllers
&lt;/h2&gt;

&lt;p&gt;On the API server, you enable them using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;--enable-admission-plugins&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;MutatingAdmissionWebhook,ValidatingAdmissionWebhook
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To verify webhook support:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl api-versions | &lt;span class="nb"&gt;grep &lt;/span&gt;admissionregistration.k8s.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;admissionregistration.k8s.io/v1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’re good to go.&lt;/p&gt;




&lt;h2&gt;
  
  
  Writing Your Own Admission Controller
&lt;/h2&gt;

&lt;p&gt;If you want to build one yourself, here’s the high-level flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build an HTTPS service&lt;/li&gt;
&lt;li&gt;Accept &lt;code&gt;AdmissionReview&lt;/code&gt; objects&lt;/li&gt;
&lt;li&gt;Return:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;allowed: true/false&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Optional JSON patch (for mutation)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Register it using:&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;MutatingWebhookConfiguration&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;or &lt;code&gt;ValidatingWebhookConfiguration&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your webhook must:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use TLS&lt;/li&gt;
&lt;li&gt;Be reachable inside the cluster&lt;/li&gt;
&lt;li&gt;Include a CA bundle in its configuration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once configured, Kubernetes will call your service every time matching resources are created, updated, or deleted.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Admission Controllers are one of the most powerful - and often overlooked - features in Kubernetes.&lt;/p&gt;

&lt;p&gt;They give you a programmable control layer inside the API server.&lt;/p&gt;

&lt;p&gt;If you’re running Kubernetes in production and not leveraging admission controllers, you’re relying entirely on developers to “do the right thing.”&lt;/p&gt;

&lt;p&gt;And we all know how that usually goes&lt;/p&gt;

&lt;p&gt;Use them wisely - and your cluster becomes significantly safer and more predictable.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>cloudnative</category>
      <category>security</category>
    </item>
  </channel>
</rss>
