What is the best way to mount files generated by one pod on another pod (before it starts) on a different node in GCP?

9/26/2019

I have a simple use case. I am trying to deploy two pods on two different nodes in Kubernetes. Pod A is a server which creates a file abc.txt after receiving an API request. I want to mount this abc.txt file onto Pod B.

If the file jhsdiak.conf (the name of this file is randomly generated) is not present on pod B before it starts, pod B will create its own default file. Hence to avoid this, the file has to be mounted onto Pod B before it starts.

Here are the things I have tried

  • Shared Volume using dynamically provisioned PVC -> This approach works fine if both the pods are created on the same node. Not otherwise as GCP doesn't support ReadWriteMany.
  • Using Kubectl CP to copy the files from Pod A to host path and then creating configmaps/secrets to mount it onto Pod B -> This approach fails as the name of file jhsdiak.conf is randomly generated.
  • InitContainers -> I am not sure how I can use an init container to move files from one pod to another.
  • Using NFS Persisted storage -> I haven't tried it yet, but seems like a lot of overhead to just move one file between pods.

Is there a better or more efficient way to solve this problem?

-- goldentiger
google-cloud-platform
kubernetes
volumes

1 Answer

9/26/2019

A similar solution is to use Cloud Storage for storing your files.

But, I have another solution than "file". Create a PubSub topic and push your files in it with Pod A. Create a pull subscription and poll it with Pod B.

You can achieve what you want, I mean sending data from A to B, and you don't have to worry about file system.

If your cluster is compliant with Knative, the eventing solution can help you for staying inside the cluster (if it's a requirement)

-- guillaume blaquiere
Source: StackOverflow