<p>The contents in my Persistent Volume is getting deleted when the StatefulSet or Deployment restarts and new Pods are getting created.</p>
<p>I thought the idea of having Persistent Volume is to have it's content persisted. So I am wondering if there is anything wrong in my configuration.</p>
<p>I have the following PVC:</p>
<pre><code>kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: sftp-pvc
  labels:
    app: sftp
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi
</code></pre>
<p>The PV as such is automatically created and managed. An example of how it looks like created by PVC above is as such:</p>
<p><a href="https://i.stack.imgur.com/69UFl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/69UFl.png" alt="Persistent Volume example" /></a></p>
<p>And then the following StatefulSet:</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: sftp-deployment
spec:
  serviceName: sftp-statfulset
  replicas: 2
  selector:
    matchLabels:
      app: sftp
  template:
    metadata:
      labels:
        app: sftp
    spec:
      volumes:
      - name: sftp-storage
        persistentVolumeClaim:
          claimName: sftp-pvc
      containers:
      - name: sftp
        image: atmoz/sftp
        ports:
        - containerPort: 22
        env:
        - name: SFTP_USERS
          value: &quot;$(SFTP_USERNAME):$(SFTP_PASSWORD):::$(SFTP_ROOT_DIRECTORY)&quot;
        volumeMounts:
        - name: ftm-sftp-storage
          mountPath: &quot;/home/$(SFTP_USERNAME)/$(SFTP_ROOT_DIRECTORY)&quot;
        resources:
          requests:
            memory: &quot;64Mi&quot;
            cpu: &quot;250m&quot;
          limits:
            memory: &quot;128Mi&quot;
            cpu: &quot;500m&quot;
</code></pre>
<p>It does not matter if the Resource is StatefulSet or Deployment.</p>
<p>So above is one SFTP server created and deployed on K8s. If I connect to it for example by using FileZilla I can create files or folders and they are being persisted if I log out and log in.</p>
<p>But as soon as the StatefulSet gets restarted and new Pods get created I lose all the files.</p>
<p>How can I make sure that the contents of the Persistent volume stay persistent no matter what is the case?</p>

f.bele
<p>As it turns out I've found out that the <code>mountPath</code> value shouldn't be put together by using environment variables. So I've set a fixed value and it worked:</p>
<pre><code>volumeMounts:
- name: sftp-storage
  mountPath: &quot;/home/user1/user-directory&quot;
</code></pre>
