<p>I'd like to be able to <strong>create a temporary container within an existing pod</strong> to handle processing arbitrary code from a user (security concerns), however <strong>this container must also in the same pod</strong> due to data locality / performance concerns.</p>
<p>My question is, what is the proper way to achieve this? <a href="https://kubernetes.io/docs/concepts/workloads/pods/ephemeral-containers/" rel="nofollow noreferrer">Ephemeral Containers</a> are described as &quot;to inspect services rather than to build applications&quot; and &quot;Ephemeral containers may not have ports&quot;.</p>
<p>So I feel that this is not the proper way to go about this. My temporary container must be able to share mounted data with the original container in the same Pod, and must be able to communicate via a port that is opened to the original container of the same Pod.</p>

jrdzha
<p>You can achieve this by either creating a <a href="https://medium.com/bb-tutorials-and-thoughts/kubernetes-learn-sidecar-container-pattern-6d8c21f873d" rel="nofollow noreferrer">sidecar</a> which will intercept the traffic to your original pod, or just creating a second pod in your deployment and a way of automatically trigger the process you wanna do. One caveat about this is that the two pods share the same network so you can not expose the same port for both containers.</p>
<p>The downside of both approaches is that you no longer have a temporary container,now you would have both up and running.</p>
<p>If what you wanna do is a one time task when your container is up I highly recommend exposing an API in your original pod and make a call from a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/" rel="nofollow noreferrer">Job</a>.</p>
