Kubernetes - Share single file between containers (within the same pod)

8/22/2019

I have an API that describes itself through an openapi3 file. This app is contained in a pod that also has a sidecar app that is supposed to read this file at startup time.

My probleme is how my sidecar app can read the openapi file from the other container ?

I know I could do it using a volume (emptyDir) and modify the command so my api copies the file at startup time. I'd rather not go this route. I have been looking for a feature, where I define a volume which is mapped to an existing folder in my app, but without being empty. Is there such a thing ?

-- benjamin.d
kubernetes
kubernetes-pod
openapi

1 Answer

8/22/2019

One of the simplest approaches is to use emptyDir: https://kubernetes.io/docs/concepts/storage/volumes/#emptydir

In your container that generates the file that needs to be shared, mount emptyDir volume with write access and copy the file there. In your sidecar that needs to read the file, mount the same volume as read only and read the file. With this pattern, all containers in the pod can have access to the same file system with read / write as needed.

-- Keilo
Source: StackOverflow