<p>I have dirctory on <code>K8</code> master server.</p>

<p>I have  20 pods (With Deployment replicas).</p>

<p>I want all pods read from master directory <code>/path/in/master/infiles</code> And write their output to same directory <code>/path/in/master/outfiles</code>, Which Volume type should I need to use at this case? I Want my files not deleted after pod die.</p>

<p>I trying to look at  the following: <a href="https://kubernetes.io/docs/concepts/storage/volumes/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/volumes/</a> but still don't know  what is the best options for my case.</p>

<p>Any suggestions?</p>

samisaviv
<p>You can use <a href="https://kubernetes.io/docs/concepts/storage/volumes/#hostpath" rel="nofollow noreferrer">hostPath</a> volume.</p>

<p>A <code>hostPath</code> volume mounts a file or directory from the host node’s filesystem into your Pod.</p>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/path/in/master/infiles"
</code></pre>

<p>Check this <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/" rel="nofollow noreferrer">guide</a> on how to use hostPath.</p>

<p>A better option would be to use <a href="https://kubernetes.io/docs/concepts/storage/volumes/#local" rel="nofollow noreferrer">local</a> volume.</p>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: example-pv
spec:
  capacity:
    storage: 100Gi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  storageClassName: local-storage
  local:
    path: "/path/in/master/infiles"
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - example-node
</code></pre>

<p>Compared to hostPath volumes, local volumes can be used in a durable and portable manner without manually scheduling Pods to nodes, as the system is aware of the volume’s node constraints by looking at the node affinity on the PersistentVolume.</p>

<p>Edit: </p>

<p>The problem with storing data in the filesystem of the nodes itself is that there is no way to sync the data between the nodes. If this is needed for the application then using a PV backed by NFS in ReadWriteMany(RWX) mode is a better option. Here is <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-readwritemany-rwx-persistent-volumes-with-nfs-on-digitalocean-kubernetes" rel="nofollow noreferrer">guide</a> on how to make this work in digital ocean.</p>
