0

See below I have directories in EFS - data and logs. Do I need to create a different PV if I need to use a subpath? And if I do, how do I specify the PV to use for the PVC?

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: efs-pv-data
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: efs-sc
  csi:
    driver: efs.csi.aws.com
    {{/*    same EFS ID*/}}
    volumeHandle: fs-ABC1234
    volumeAttributes:
      path: /data

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: efs-pv-logs
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: efs-sc
  csi:
    driver: efs.csi.aws.com
    {{/*    same EFS ID*/}}
    volumeHandle: fs-ABC1234
    volumeAttributes:
      path: /logs

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: efs-claim-data
  namespace: my-app
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: "efs-sc"
  resources:
    requests:
      storage: 5Gi
Mr.KoopaKiller
  • 3,665
  • 10
  • 21
alltej
  • 6,787
  • 10
  • 46
  • 87
  • I tested it and looks like this is not possible. But the PV and the PVC status says it is `Bound`. To me that status means it is ready and can be mounted to the pod or containers. But when mounting the volume to the container, it will get an error `Unable to mount volumes ...` – alltej Feb 28 '20 at 18:10
  • Do I need to create a different StorageClass for each path? – alltej Feb 28 '20 at 19:13

1 Answers1

0

I've confirmed that it works with an almost identical setup. It looks like what you're missing is the volumeName attribute of the pvc, which binds it to a specific pv.

e.g:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: testpvc
  namespace: apis
spec:
  resources:
    requests:
      storage: 5Gi
  volumeMode: Filesystem
  storageClassName: efs-sc
accessModes:
  - ReadWriteMany
volumeName: example-pv

Also, I'm using EFS AccessPoints so that if the path does not exist on the EFS filesystem it can be created automatically (more info here).

It can be then used like that in the pv, instead of using path:

kind: PersistentVolume
metadata:
  name: example-pv
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: efs-sc
  csi:
    driver: efs.csi.aws.com
    volumeHandle: fs-xxxxxxxxxx::fsap:xxxxxxxxx

I hope people find this useful because I've struggled with provisioning a big amount of pvs and pvcs relating to the same efs.