rancher / local-path-provisioner

Dynamically provisioning persistent local storage with Kubernetes
Apache License 2.0
2.15k stars 448 forks source link

Questions on multiple pods accessing same PVC/PV (ReadWriteOnce) using local path provisioner #434

Open cwrx777 opened 1 month ago

cwrx777 commented 1 month ago

I have created a PV with the following yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: {{ $.Release.Name }}-db-primary-data-pv
  labels:
    component: primary-data
    app.kubernetes.io/component: primary-data
spec:
  storageClassName: local-path
  capacity:
    storage: {{ $.Values.primary.persistence.data.size }}
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  local:
    path: {{ tpl .Values.primary.persistence.data.hostPath . }}
  nodeAffinity: 
    required:
      nodeSelectorTerms:
        - matchExpressions:
            - key: {{ $.Values.global.pv.nodeAffinity.selector.key }}
              operator: In
              values:
                -  {{ $.Values.global.pv.nodeAffinity.selector.value }}

and this PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: {{ $.Release.Name }}-db-primary-data-pvc
  labels:
    component: primary-data
    app.kubernetes.io/component: primary-data
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: {{ $.Values.primary.persistence.data.size }}
  storageClassName: local-path
  selector:
    matchLabels:
      component: primary-data

And I want to create two pods, e.g. mysql and mysql-backup, both pods are running in the same node, to be able to access the PV, in the same node as the pods, for accessing mysql data-dir at the same time. both pods are using the same PVC. Will that work?

I have created two pods in k3s with volume using the same PVC. In both pods (deployed using helm twice, with different release name), I can see the directory. but only one of the pod can browse the directory whereas the other one encountered 'permission denied' error.

- PVC
```yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    meta.helm.sh/release-name: fb-store
    meta.helm.sh/release-namespace: rmf
    pv.kubernetes.io/bind-completed: "yes"
    pv.kubernetes.io/bound-by-controller: "yes"
    volumeType: local
  creationTimestamp: "2024-07-18T21:51:30Z"
  finalizers:
  - kubernetes.io/pvc-protection
  labels:
    app: fb-store-fb-db
    app.kubernetes.io/managed-by: Helm
  name: fb-store-fb-db-pvc
  namespace: rmf
  resourceVersion: "2790323"
  uid: 38eb3f70-db76-489d-b1a1-939c3a78920d
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Mi
  selector:
    matchLabels:
      app: fb-store-fb-db
  storageClassName: local-path
  volumeMode: Filesystem
  volumeName: fb-store-fb-db-pv
status:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 10Mi
  phase: Bound

folder permission in host:

drwxrws---. 2 username 2000 25 Jul 19 06:06 db
drwxrws---. 2 username 2000 21 Jul 19 06:08 rootDir
cwrx777 commented 1 month ago

i also tested using the following:

only one of the pod is able to write to /mnt/shared.log


I also notice this event:

running PreBind plugin "VolumeBinding": Operation cannot be fulfilled on persistentvolumeclaims "test-pvc": the object has been modified; please apply your changes to the latest version and try again