<p>I am designing a Kubernetes system which will require storing audio files. To do this I would like to setup a persistent storage volume making use of a stateful set.</p>
<p>I have found a few tutorials on how to set something like this up, but I am unsure once I have created it how to read/write the files. What would be the best approach to do this. I will be using a flask app, but if I could just get a high level approach then I can find the exact libraries myself.</p>

EoinHanan
<p>Not acknowledging on facts how it should be implemented programming wise and the specific tuning for dealing with audio files, you can use your <code>Persistent Volume</code> the same as you would read/write data to a directory (as correctly pointed by user @zerkms in the comments).</p>
<p>Answering this specific part of the question:</p>
<blockquote>
<p>but I am unsure once I have created it how to read/write the files.</p>
</blockquote>
<p>Assuming that you've created your <code>StatefulSet</code> in a following way:</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: ubuntu-sts
spec:
  selector:
    matchLabels:
      app: ubuntu # has to match .spec.template.metadata.labels
  serviceName: &quot;ubuntu&quot;
  replicas: 1
  template:
    metadata:
      labels:
        app: ubuntu
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: ubuntu
        image: ubuntu
        command:
        - sleep 
        - &quot;infinity&quot; 
        volumeMounts:
        - name: audio-volume
          mountPath: /audio 
  volumeClaimTemplates: 
  - metadata:
      name: audio-volume
    spec:
      accessModes: [ &quot;ReadWriteOnce&quot; ]
      storageClassName: standard
      resources:
        requests:
          storage: 1Gi
</code></pre>
<p>Take a look on below part (it's showing where your <code>Volume</code> will be mounted):</p>
<pre><code>        volumeMounts:
        - name: audio-volume
          mountPath: /audio # &lt;-- HERE!
</code></pre>
<blockquote>
<p>Disclaimer!</p>
<p>This example is having the 1:1 <code>Pod</code> to <code>Volume</code> relation. If your use case is different you will need to refer to the Kubernetes documentation about <code>accessModes</code>.</p>
</blockquote>
<p>You can <code>exec</code> into this <code>Pod</code> to look how you can further develop your application:</p>
<ul>
<li><code>$ kubectl exec -it ubuntu-sts-0 -- /bin/bash</code></li>
<li><code>$ echo &quot;Hello from your /audio directory!&quot; &gt; /audio/hello.txt</code></li>
<li><code>$ cat /audio/hello.txt</code></li>
</ul>
<pre class="lang-sh prettyprint-override"><code>root@ubuntu-sts-0:/# cat /audio/hello.txt 
Hello from your /audio directory!
</code></pre>
<hr />
<blockquote>
<p>A side note!</p>
<p>If it happens that you are using the cloud-provider managed Kubernetes cluster like <code>GKE</code>, <code>EKS</code> or <code>AKS</code>, please refer to it's documentation about storage options.</p>
</blockquote>
<p>I encourage you to check the official documentation on <code>Persistent Volumes</code>:</p>
<ul>
<li><em><a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">Kubernetes.io: Docs: Concepts: Storage: Persistent Volumes</a></em></li>
</ul>
<p>Also, please take a look on documentation regarding <code>Statefulset</code>:</p>
<ul>
<li><em><a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">Kubernetes.io: Docs: Concepts: Workloads: Controllers: Statefulset</a></em></li>
</ul>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://www.guru99.com/reading-and-writing-files-in-python.html" rel="nofollow noreferrer">Guru99.com: Reading and writing files in Python</a></em></li>
</ul>
