Create a Kyverno mutate policy to add a default resource limits sidecar annotation to Deployments

domain: kyverno.io · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Author a `ClusterPolicy` (or `MutatingPolicy` if using Kyverno 1.17+ CEL APIs) with `spec.rules[].mutate.patchStrategicMerge` targeting `Deployment` resources in all namespaces.
  2. Use a `patchStrategicMerge` patch or a `foreach` loop with `patchesJson6902` to add annotations or inject default resource limits when they are absent.
  3. Set `spec.rules[].match.any[].resources.kinds: [Deployment]` and `spec.rules[].mutate.patchStrategicMerge` to add the annotation key conditionally using `+(key): value` syntax (the `+` prefix is a Kyverno strategic merge addition anchor).
  4. Test the mutation locally with `kyverno apply policy.yaml --resource deployment.yaml` and inspect the mutated output.
  5. Deploy the policy to the cluster and verify by creating a test Deployment without the target annotation; `kubectl describe` should show the annotation injected by Kyverno.
  6. Use `spec.failureAction` is not applicable for mutate rules; ensure the admission webhook is healthy by checking Kyverno pod logs.

Known gotchas

Related routes

Write a Kyverno mutate policy to inject a sidecar container into Deployments
kyverno.io · 6 steps · unrated
Write a Kyverno mutate policy using patchStrategicMerge to add default resource limits to containers that omit them
security/compliance · 5 steps · unrated
Author a Kyverno ClusterPolicy with mutate rules to inject resource limits and requests on pods that omit them, and validate the policy with Kyverno CLI test cases
kyverno.io · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans