The contents in my Persistent Volume is getting deleted when the StatefulSet or Deployment restarts and new Pods are getting created.
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.
I have the following PVC:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: sftp-pvc
labels:
app: sftp
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
The PV as such is automatically created and managed. An example of how it looks like created by PVC above is as such:
And then the following StatefulSet:
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: "$(SFTP_USERNAME):$(SFTP_PASSWORD):::$(SFTP_ROOT_DIRECTORY)"
volumeMounts:
- name: ftm-sftp-storage
mountPath: "/home/$(SFTP_USERNAME)/$(SFTP_ROOT_DIRECTORY)"
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
It does not matter if the Resource is StatefulSet or Deployment.
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.
But as soon as the StatefulSet gets restarted and new Pods get created I lose all the files.
How can I make sure that the contents of the Persistent volume stay persistent no matter what is the case?

As it turns out I've found out that the
mountPathvalue shouldn't be put together by using environment variables. So I've set a fixed value and it worked: