I need to add an sidecar to run alongside my main container in K8S during runtime. I have currently done this using a script which edits the deployment.yaml to add all necessary parts including the container and any shared volume mounts etc. This currently works but is a bit ugly. I started looking at Istio for automatic sidecar injection but the documentation is a bit unclear to me.
istio, as many other kube-native apps, uses k8s admission-controller and the admission-webhooks api to patch the deployment and inject the sidecar, take a look at https://github.com/istio/istio/blob/master/pkg/kube/inject/inject.go