PodPresets (Legacy)

Difficulty: Advanced

Question

What were PodPresets in Kubernetes, why were they removed, and what do teams use instead today?

Answer

PodPresets were an alpha Kubernetes API (settings.k8s.io/v1alpha1) that automatically injected environment variables, envFrom sources, volumes and volume mounts into Pods at creation time, based on a label selector in the same namespace. They let platform teams add shared configuration such as a database Secret or a common cache volume without every app team editing its manifests. PodPresets never left alpha and were removed in Kubernetes 1.20; today the same job is done with mutating admission webhooks, policy engines like Kyverno, or the newer built-in MutatingAdmissionPolicy.

How PodPresets worked

  1. A cluster admin enabled the settings.k8s.io/v1alpha1 API and the PodPreset admission plugin on the API server.
  2. A team created a PodPreset in a namespace with a selector such as role: frontend.
  3. When a Pod matching the selector was created, the admission plugin merged the preset's env, volumes and mounts into every container.
  4. The Pod got an annotation recording which preset was applied.

If the injected data conflicted with what the Pod already defined, the preset was not applied and an event was recorded.

Why they were removed

  • They stayed alpha for years, so they were off by default and rarely enabled on managed clusters.
  • Their scope was narrow: only env, envFrom, volumes and mounts, with no conditions, no image changes and no sidecars.
  • Mutating admission webhooks, which became generally available earlier, could do everything PodPresets did and much more.
  • Silent injection made Pods harder to understand, since the running spec differed from the manifest in Git.

What replaced them

OptionHow it worksTypical use
Mutating admission webhookYour HTTPS service receives the object and returns a JSON patchIstio and Linkerd sidecar injection, Vault Agent injector
Kyverno mutate policiesDeclarative YAML policies, run as a webhookAdd labels, default resources, inject env or volumes
OPA Gatekeeper mutationAssign and AssignMetadata resourcesOrg-wide defaults with Rego-based validation
MutatingAdmissionPolicyBuilt-in, CEL-based, no webhook server neededSimple in-process mutations (newer, beta in recent releases)
Helm or KustomizeInject at build time, before applyKeeps the mutation visible in Git

Trade-offs of runtime injection

  • Pros: central enforcement, app teams do not need to know about platform concerns, works for every Pod including ones created by third-party charts.
  • Cons: drift between Git and the live spec, webhook latency and availability risk (a down webhook with failurePolicy: Fail can block all Pod creation), and harder debugging.

If you answer this in an interview, frame PodPresets as history and spend most of the time on how admission control works now. That is what the interviewer really wants to hear.

Where Pod mutation happens in the API request path. PodPresets ran at the mutating admission step, which webhooks and policies now handle.
  1. kubectl apply sends Pod: Request reaches the API server.
  2. Authentication and RBAC: Who are you and are you allowed?
  3. Mutating admission: PodPreset, webhooks or Kyverno modify the Pod.
  4. Validating admission: Policies accept or reject the final object.
  5. Persisted to etcd: The scheduler then sees the mutated Pod.

Code examples

Kyverno policy that does what a PodPreset used to do

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: inject-redis-config
spec:
  rules:
    - name: add-redis-env
      match:
        any:
          - resources:
              kinds: ["Pod"]
              selector:
                matchLabels:
                  uses-cache: "true"
      mutate:
        patchStrategicMerge:
          spec:
            containers:
              - (name): "*"            # every container in the Pod
                env:
                  - name: REDIS_HOST
                    value: redis.cache.svc.cluster.local
                  - name: REDIS_PORT
                    value: "6379"

Any Pod labelled `uses-cache: "true"` gets the Redis settings injected at admission time, which is exactly the PodPreset use case with a supported, actively maintained tool.

Key points

  • PodPresets were alpha (`settings.k8s.io/v1alpha1`) and removed in Kubernetes 1.20.
  • They injected env, envFrom, volumes and volume mounts based on a label selector.
  • Mutating admission webhooks, Kyverno and Gatekeeper mutation replaced them.
  • MutatingAdmissionPolicy offers CEL-based mutation without running a webhook server.
  • Runtime injection trades visibility in Git for central enforcement.

Common follow-up questions

  • What is the difference between mutating and validating admission controllers?
  • How does Istio inject its sidecar into Pods?
  • What happens to Pod creation if a mutating webhook is down?
  • Would you inject config at admission time or at build time with Kustomize? Why?

Interview tips

  • Say up front that PodPresets are removed; answering as if they are current is a red flag.
  • Pivot to admission control, which is the concept the question is really testing.
  • Mention webhook failure policy risks to show production awareness.

Concepts covered

PodPreset, Mutating Admission Webhook, Kyverno, MutatingAdmissionPolicy, Admission Control

More Kubernetes & Orchestration questions