Course contentsShow
← Cloud and Infrastructure
Lesson 1410 of 2,98928. Kubernetes SecurityFree lesson

Mutating Admission Webhooks

Creating mutating webhooks to modify objects before persistence, such as injecting sidecars or setting defaults automatically.

Mutating Admission Webhooks

What you'll learn: How mutating admission webhooks automatically modify Kubernetes objects before they're stored, enabling powerful automation like sidecar injection and default value enforcement.

What Is a Mutating Admission Webhook?

A mutating admission webhook is a custom HTTP callback that intercepts API requests before objects are persisted to etcd. Unlike validating webhooks (which only approve or reject), mutating webhooks can change the resource definition on-the-fly.

Think of it as an assembly line inspector who doesn't just check quality—they actually add missing parts or adjust specifications before the product ships to the warehouse.

How It Works

When you create or update a resource (like a Pod), the API server:

  1. Receives your request
  2. Calls registered mutating webhooks in order
  3. Applies the webhook's modifications to your object
  4. Continues with validation and persistence

Your webhook receives a JSON AdmissionReview containing the original object and returns a JSON Patch describing what to change.

Common Use Cases

Sidecar Injection: Service meshes like Istio automatically inject proxy containers into every Pod without you manually adding them.

Default Values: Automatically set resource limits, labels, or environment variables when developers omit them.

Policy Enforcement: Add security contexts, mount volumes, or inject secrets based on namespace or other attributes.

Configuration Normalization: Convert user-friendly inputs into the exact format required by your infrastructure.

Why It Matters

Mutating webhooks enable invisible automation that reduces toil and enforces standards without requiring every team member to remember complex configurations. They're the "autocorrect" of Kubernetes—making deployments safer and more consistent.

Key Takeaway:
Mutating admission webhooks transform Kubernetes resources automatically before storage, enabling powerful patterns like sidecar injection and policy-driven defaults without manual configuration changes.