Injecting a volumeMount in kubernetes

10/16/2019

Is it possible to inject a volumeMount and a volume to an existing container (within the yaml file to be deployed) using a webhook or using Istio? Most places only discuss how to add Sidecar containers with their volume Mounts. If it is not possible to inject a volumeMount what would be the best way to approach it?

-- JAbeywrdana
istio
kubernetes

1 Answer

10/16/2019

You can use a MutatingAdmissionController webhook to modify the YAML in any way you like. So, yes, you can configure volume mounts as well. Another approach would be to use kustomize or helm to use a templated configuration and modify it appropriately when applying it.

Here is a python example to add the ttlSecondsAfterFinished spec to a job: https://www.trion.de/news/2019/04/25/beispiel-kubernetes-mutating-admission-controller.html In a similar way you could add volumes.

-- Thomas
Source: StackOverflow