πŸ“šBook Signing at KubeCon EU 2026Meet us at Booking.com HQ (Mon 18:30-21:00) & vCluster booth #521 (Tue 24 Mar, 12:30-1:30pm) β€” free book giveaway!RSVP Booking.com Event
Security advanced ⏱ 15 minutes K8s 1.28+

Kubernetes Admission Controllers and Webhooks

Build validating and mutating admission webhooks for Kubernetes. Policy enforcement with OPA Gatekeeper, Kyverno, and custom webhooks.

By Luca Berton β€’ β€’ πŸ“– 5 min read

πŸ’‘ Quick Answer: Build validating and mutating admission webhooks for Kubernetes. Policy enforcement with OPA Gatekeeper, Kyverno, and custom webhooks.

The Problem

This is a critical skill for managing production Kubernetes clusters at scale. Without it, teams face operational complexity, security risks, and reliability issues.

The Solution

Admission controllers intercept API requests after authentication and before persistence. Prefer a policy engine over hand-written webhooks for most rules. This Kyverno policy enforces a required team label on every Pod:

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: require-team-label
spec:
  validationFailureAction: Enforce
  rules:
    - name: check-team-label
      match:
        any:
          - resources:
              kinds: ["Pod"]
      validate:
        message: "Every Pod must set a 'team' label."
        pattern:
          metadata:
            labels:
              team: "?*"

For lower-level control, register a webhook with failurePolicy: Fail so requests are rejected when the webhook is unavailable (fail-closed):

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
  name: pod-policy
webhooks:
  - name: pods.example.com
    failurePolicy: Fail
    admissionReviewVersions: ["v1"]
    sideEffects: None
    rules:
      - apiGroups: [""]
        apiVersions: ["v1"]
        operations: ["CREATE"]
        resources: ["pods"]
    clientConfig:
      service:
        name: pod-policy-webhook
        namespace: policy-system
        path: /validate

Use mutating webhooks to inject defaults (sidecars, labels) and validating webhooks to reject non-compliant objects.

Common Issues

Troubleshooting

Check logs and events first. Most issues have clear error messages pointing to the root cause.

Best Practices

  • Follow the principle of least privilege for all configurations
  • Test in staging before applying to production
  • Monitor and alert on key metrics
  • Document your runbooks for the team

Key Takeaways

  • Essential knowledge for Kubernetes operations at scale
  • Start simple and evolve your approach as needed
  • Automation reduces human error and operational toil
  • Share learnings across your team
#admission-controllers #webhooks #opa #kyverno #policy #kubernetes
Luca Berton
Written by Luca Berton

Principal Solutions Architect specializing in Kubernetes, AI/GPU infrastructure, and cloud-native platforms. Author of Kubernetes Recipes and creator of CopyPasteLearn courses.

Kubernetes Recipes book cover

Want More Kubernetes Recipes?

This recipe is from Kubernetes Recipes, our 750-page practical guide with hundreds of production-ready patterns.

Luca Berton Ansible Pilot Ansible by Example Open Empower K8s Recipes Terraform Pilot CopyPasteLearn ProteinLens