How to create and mount common data for all pods

10/26/2019

I have defined job in my kubernetes cluster which suppose to create some folder with some data. Now I would like to share this folder between all other pods, because they need to use this data.

Currently other pods are not running if above mentioned job is not finished.

So I think about volumes. Let's say - result of the job is mounted folder, which is accessible from other pods when job is finished.

Other pods in cluster needs only environment variable - path to this mounted folder.

Could you please how I could define this?

ps. I know this is not a very good use case, however I Have legacy monolit application with lots of dependencies.

-- liotur
deployment
docker
kubernetes
kubernetes-helm
pod

1 Answer

10/26/2019

I'm assuming that the folder you are referring to is a single folder at some disk that can be mounted by multiple clients.

  • Check here , or at your volume plugin documentation reference if the access mode you are requesting is supported.
  • Create the persistent volume claim that your pods will use, no need for the matching volume to exists yet. You can use label/expression matching to make sure that this PVC will only be satisfied by the persistent volume you will be creating at your job.
  • At your job add a final task that creates the persistent volume claim that satisfies the PVC.
  • Create your pods adding the PVC as volume. I don't think pod presets are needed, plus they are alpha, not enabled by default, and not widely used, but depending on your case you might want to take a look at them.
-- Pablo Mercado
Source: StackOverflow