3

I have a kubernetes PersistentVolume resource defined which uses the efs.csi.aws.com driver. My question is, I want to specify the target path for this volume (/app_data). But this folder needs to exists first before I can start mounting them to the container with PersistentVolumeClaims otherwise it will get error that the target path does not exists. I thought that the folder can be created in the AWS UI or CLI when provisioning the EFS. Something like an S3 where you can create a bucket in the AWS web UI.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: app-pv
  namespace: my-app
spec:
  capacity:
    storage: 10Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  storageClassName: app-efs-sc
  csi:
    driver: efs.csi.aws.com
    volumeHandle: fs-1234567
    volumeAttributes:
      path: "/app_data"
alltej
  • 6,787
  • 10
  • 46
  • 87
  • Am I right that the goal is to have `/app_data` dir on `app-pv` PV , attached to some pod by PVC? – Nick Mar 12 '20 at 13:14
  • 1
    yes. my workaround is to use `subPath` when mounting the volume in the container. – alltej Mar 12 '20 at 16:31

1 Answers1

0

It is not a production like sollution but may work as workaround. I would suggest to use initContainer for this task. You can mount whole fs in init container and create directory + assign access right there. Here are example answer

user2986553
  • 121
  • 3
  • It becomes a chicken and egg problem. So even with `initContainer` you need the the `PersistentVolume` and `PersistentVolumeClaims` to mount it and therefore you will also get the error since the path did not exists. – alltej Mar 11 '20 at 14:04
  • yes, but you may create a separate persistent volume for init container with same fs-id but mounted as / for `initContainer`. There you can call something like `mkdir -p /app_data` - i believe this step will be idempotent and even if directory exist it won't change nothing. – user2986553 Mar 11 '20 at 14:11
  • So I need to create a PVC also for that separate PV since one PV is map to one PVC. And how do I specify in the PVC to use this PV? I did not see an attribute to map a PVC to PV. – alltej Mar 11 '20 at 14:20
  • 1
    Especially I made similar configuration by mapping pv pvc with same [storageClassName](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#class) attribute - it is a string. But seems that there are at least [one more](https://stackoverflow.com/a/49785697/2986553) way to do this. Also I found [issue in github that may be related to your question](https://github.com/kubernetes-sigs/aws-efs-csi-driver/issues/6) and it is still open. – user2986553 Mar 11 '20 at 14:30