Modify pod on creation

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

You can use something like metacontroller to mutate pod requests and add things like env vars :slight_smile:

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.

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 :slight_smile:

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