<p>I have a fileserver with a folder <code>/mnt/kubernetes-volumes/</code>. Inside this folder, I have subdirectories for every user of my application:</p>
<ul>
<li><code>/mnt/kubernetes-volumes/customerA</code></li>
<li><code>/mnt/kubernetes-volumes/customerB</code></li>
<li><code>/mnt/kubernetes-volumes/customerC</code></li>
</ul>
<p>Inside each customer folder, I have two folders for the applications of my data stores:</p>
<ul>
<li><code>/mnt/kubernetes-volumes/customerA/elastic</code></li>
<li><code>/mnt/kubernetes-volumes/customerA/postgres</code></li>
</ul>
<p>I have a Kubernetes configuration file that specifies persistent volumes and claims. These mount to the <code>elastic</code> and <code>postgres</code> folders.</p>
<pre><code># Create a volume on the NFS disk that the postgres db can use. 
apiVersion: v1
kind: PersistentVolume
metadata:
  namespace: customerA
  name: postgres-pv
  labels:
    name: postgres-volume 
spec:
  storageClassName: manual 
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  nfs:
    server: 1.2.3.4 # ip addres of nfs server
    path: &quot;/mnt/kubernetes-volumes/customerA/postgres&quot; 

---

# And another persistent volume for Elastic
</code></pre>
<p>Currently, my <code>/etc/exports</code> file looks like this:</p>
<pre><code>/mnt/kubernetes-volumes/customerA/postgres 10.0.0.1(rw,sync,no_subtree_check,no_root_squash)
/mnt/kubernetes-volumes/customerA/elastic 10.0.0.1(rw,sync,no_subtree_check,no_root_squash)
/mnt/kubernetes-volumes/customerA/postgres 10.0.0.2(rw,sync,no_subtree_check,no_root_squash)
/mnt/kubernetes-volumes/customerA/elastic 10.0.0.2(rw,sync,no_subtree_check,no_root_squash)


/mnt/kubernetes-volumes/customerB/postgres 10.0.0.1(rw,sync,no_subtree_check,no_root_squash)
/mnt/kubernetes-volumes/customerB/elastic 10.0.0.1(rw,sync,no_subtree_check,no_root_squash)
/mnt/kubernetes-volumes/customerB/postgres 10.0.0.2(rw,sync,no_subtree_check,no_root_squash)
/mnt/kubernetes-volumes/customerB/elastic 10.0.0.2(rw,sync,no_subtree_check,no_root_squash)
</code></pre>
<p>For every customer, I explicitly export a <code>postgres</code> and <code>elastic</code> folder separately for every node in my Kubernetes cluster. This works as intended. However, I now have to manually add rows to the <code>etc/exports</code> file for every new customer. Is it possible to have just two lines like this:</p>
<pre><code>/mnt/kubernetes-volumes/ 10.0.0.1(rw,sync,no_subtree_check,no_root_squash)
/mnt/kubernetes-volumes/ 10.0.0.2(rw,sync,no_subtree_check,no_root_squash)
</code></pre>
<p>And automatically have Kubernetes create the correct sub-directories (customer, postgres and elastic) inside the <code>kubernetes-volumes</code> directory and mount them?</p>

yesman
<p>Kubernetes can't perform system commands on nodes by itself, you need to use some external tool, such as bash script.</p>
<p>You can use only the path <code>/mnt/kubernetes-volumes/</code> in you containers and using environment variable you can pass the customer name, but it will make all data acessible by all other pods, and isn't a good idea.</p>
<p>Also, you could try to use <a href="https://helm.sh/docs/chart_template_guide/getting_started/" rel="nofollow noreferrer">HELM templates</a> to create your <code>persistentVolumes</code> using the name of your customers as variables.</p>
