I am having a simple StatefulSet deployed on K8S:
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: sftp
labels:
app: sftp
spec:
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
protocol: TCP
envFrom:
- secretRef:
name: secret
env:
- name: SFTP_USERS
value: >-
$(SFTP_USERNAME):$SFTP_PASSWORD)::$(SFTP_GID):$(SFTP_ROOT_DIRECTORY)
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 250m
memory: 64Mi
volumeMounts:
- name: sftp-storage
mountPath: /home/user1
imagePullPolicy: IfNotPresent
securityContext:
fsGroup: 10001
And my storage volume declaration is using a PVC as follows:
kind: PersistentVolumeClaim
metadata:
name: sftp-pvc
labels:
app: sftp
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
volumeName: pv-shoot--kyma--c-5f908c9-5ae6d56b-6560-4b00-9018-b17582336930
storageClassName: files
volumeMode: Filesystem
I thought that a setup like that should work without any issues, so that there wouldn't be any errors having 2 replicas on Stateful Set accessing one source on Persistant volume, but I am getting following messages on one of replica instances:
MountVolume.WaitForAttach failed for volume "pv-shoot--kyma--c-5f908c9-5ae6d56b-6560-4b00-9018-b17582336930" : volume attachment is being deleted
That is because the other instance is already attached to this volume.
What am I doing wrong here, can anyone help?
I think that it should be possible that multiple replica instances of the same Deployment or Stateful Set could access the same volume, or am I mistaken?
You're doing it completely the read
accessModeswhich you're using allows only one pod to be attached. you cannot attach not more than one pod. the correctaccessModesyou should be using isReadWriteMany- the volume can be mounted as read-write by many nodes.Create a new
PersistentVolumeClaimwithReadWriteManyasaccessModes.Also since the service you're deploying is
sftp. by its nature if you want to run more replicas and should have a same storage attached to meaning you need to have an underlyingNASstorage which can be shared across multiple deployments.storageclass.pvcwithReadWriteMany