# Modify pod on creation

**URL:** <https://discuss.kubernetes.io/t/modify-pod-on-creation/8244>\
**Category:** General Discussions\
**Created:** [October 8, 2019, 8:23am UTC](https://discuss.kubernetes.io/t/modify-pod-on-creation/8244 "2019-10-08T08:23:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_Kubu](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/roman_kubu/32/2410_2.png) [@Roman\_Kubu](https://discuss.kubernetes.io/u/Roman_Kubu)\
**Post date:** [October 8, 2019, 8:23am UTC](https://discuss.kubernetes.io/t/modify-pod-on-creation/8244/1 "2019-10-08T08:23:47Z")

</div>

Is there a way how to modify all pods created in cluster? For example to add new env variable to all pods?

---

<div class="post-metadata">

**Author:** ![mrbobbytables](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/mrbobbytables/32/7_2.png) [@mrbobbytables](https://discuss.kubernetes.io/u/mrbobbytables)\
**Post date:** [October 8, 2019, 2:16pm UTC](https://discuss.kubernetes.io/t/modify-pod-on-creation/8244/2 "2019-10-08T14:16:45Z")

</div>

You can use something like [metacontroller](https://github.com/GoogleCloudPlatform/metacontroller) to mutate pod requests and add things like env vars 🙂

If it’s a bit more complicated on deciding what to do, you may want to look into creating your thing that can mutate pod requests via [mutating admission webhooks](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/).

---

<div class="post-metadata">

**Author:** ![rata](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/rata/32/18244_2.png) [@rata](https://discuss.kubernetes.io/u/rata)\
**Post date:** [October 8, 2019, 5:56pm UTC](https://discuss.kubernetes.io/t/modify-pod-on-creation/8244/3 "2019-10-08T17:56:02Z")

</div>

Didn’t know about this, very nice!

That being said, in my experience is also useful to double check if it makes sense to do this. In my experience, sometimes it may seem appealing to reduce some duplication in yamls, etc. But sometimes duplication is not that bad and can help to make things explicit and not have “magic” variables that other people don’t understand where they come from. It can also make debugging harder, etc. So it is really a trade-off, and of course there are cases where it makes sense, but sometimes things can be done in a simpler way.

Also, things might be possible to automate in another layer (like a script before submitting the yaml, in your CD pipeline or whatever).

Just to keep your options open. But of course, you might have already considered this and it may make total sense to use those tools. Sorry if that is the case 🙂

---

<div class="post-metadata">

**Author:** ![feloy](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/feloy/32/3669_2.png) [@feloy](https://discuss.kubernetes.io/u/feloy)\
**Post date:** [October 8, 2019, 7:04pm UTC](https://discuss.kubernetes.io/t/modify-pod-on-creation/8244/4 "2019-10-08T19:04:00Z")

</div>

You can also use Kustomize and patch multiple objects plugin, that is able to patch several objects, based on their kind, labels, annotations or names

> <https://github.com/kubernetes-sigs/kustomize/blob/master/examples/patchMultipleObjects.md>
