https://rancher.com/ logo
Title
h

hundreds-airport-66196

02/14/2023, 6:06 PM
Hi All, I have a 3-node cluster with rke2. Planning of using Longhorn for PVs. How can one volume be access by any of the pods running on each of the nodes and have Read/Write access? Or do I need 3 volumes for each pod and replication takes place behind the scene. Thanks!
n

narrow-egg-98197

02/15/2023, 12:54 AM
Hi @hundreds-airport-66196, the Longhorn will create volume device and format (xfs/ext4) with StorageClass parameter specified and has the read/write authority for the bounded PVC/POD.
h

hundreds-airport-66196

02/15/2023, 6:48 AM
Yes, but what about in an HA environment (3-node) where 2 other pods are running in the other 2 nodes. Can a volume do a multi-attach from the other 2 pvc/pods? so, in this case the volume will be shared. Thanks
n

narrow-egg-98197

02/15/2023, 10:49 AM
Sure, you can let multiple pods share one Longhorn volume/PV.
Here is the yaml file for reference
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: longhorn-volv-pvc-2
  namespace: default
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 50Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: volume-test-2
  namespace: default
spec:
  restartPolicy: Always
  containers:
  - name: volume-test
    image: nginx:stable-alpine
    imagePullPolicy: IfNotPresent
    livenessProbe:
      exec:
        command:
          - ls
          - /data/lost+found
      initialDelaySeconds: 5
      periodSeconds: 5
    volumeMounts:
    - name: volv
      mountPath: /data
    ports:
    - containerPort: 80
  volumes:
  - name: volv
    persistentVolumeClaim:
      claimName: longhorn-volv-pvc-2
---
apiVersion: v1
kind: Pod
metadata:
  name: volume-test-3
  namespace: default
spec:
  restartPolicy: Always
  containers:
  - name: volume-test
    image: nginx:stable-alpine
    imagePullPolicy: IfNotPresent
    livenessProbe:
      exec:
        command:
          - ls
          - /data/lost+found
      initialDelaySeconds: 5
      periodSeconds: 5
    volumeMounts:
    - name: volv
      mountPath: /data
    ports:
    - containerPort: 80
  volumes:
  - name: volv
    persistentVolumeClaim:
      claimName: longhorn-volv-pvc-2
h

hundreds-airport-66196

02/15/2023, 1:27 PM
Thanks @narrow-egg-98197 I will check this out
😁 1
Ah, here's the issue that I found. If I move the second pod to another node, I get this error: Normal Scheduled 37s default-scheduler Successfully assigned default/volume-test-3 to node-2 Warning FailedAttachVolume 38s attachdetach-controller Multi-Attach error for volume "pvc-17688251-ae9e-41d2-817c-70564f2cc9db" Volume is already used by pod(s) volume-test-2 My understanding is Longhorn will not allow multi writes from different nodes.
n

narrow-egg-98197

02/16/2023, 10:57 AM
Sorry, I forgot to modify the PVC access mode as
ReadWriteMany
. Could you try it again?
h

hundreds-airport-66196

02/16/2023, 2:26 PM
oh yeah, it works. How was it possible, I have not find that in the docs. Can you point me to the right direction? many thanks!!!
🎉 1
n

narrow-egg-98197

02/16/2023, 2:33 PM
There are some information from here which is regarding to how Longhorn support RWX volume.
👋 1