How do I mount data into persisted storage on Kubernetes and share the storage amongst multiple pods?

9/10/2019

I am new at Kubernetes and am trying to understand the most efficient and secure way to handle sensitive persisted data that interacts with a k8 pod. I have the following requirements when I start a pod in a k8s cluster:

  • The pod should have persisted storage.
  • Data inside the pod should be persistent even if the pod crashes or restarts.
  • I should be able to easily add or remove data from hostPath into the pod. (Not sure if this is feasible since I do not know how the data will behave if the pod starts on a new node in a multi node environment. Do all nodes have access to the data on the same hostPath?)

Currently, I have been using StatefulSets with a persistent volume claim on GKE. The image that I am using has a couple of constraints as follows:

  • I have to mount a configuration file into the pod before it starts. (I am currently using configmaps to pass the configuration file)
  • The pod that comes up, creates its own TLS certificates which I need to pass to other pods. (Currently I do not have a process in place to do this and thus have been manually copy pasting these certificates into other pods)

So, how do I maintain a common persisted storage that handles sensitive data between multiple pods and how do I add pre-configured data to this storage? Any guidance or suggestions are appreciated.

-- goldentiger
google-kubernetes-engine
kubernetes
persistent-volumes
volumes

1 Answer

9/10/2019

I believe this documentation on creating a persistent disk with multiple readers [1] is what you are looking for. you will however only be able to have the pods read from the disk since GCP does not support "WRITEMANY".

Regarding hostpaths, the mount point is on the pod the volume is a directory on the node. I believe the hostpath is confined to individual nodes.

[1] https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/readonlymany-disks [2] https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes

-- Alexandre
Source: StackOverflow