Preparing MongoDB Storage
About this task
Follow the steps below to create the EFS access point, Persistent Volume (PV), and Persistent Volume Claim (PVC) for MongoDB.
Procedure
-
Create an EFS access point for MongoDB. The root
directory for this access point will be
/bitnami/mongodb:
EFS_AP_MONGODB=$(aws efs create-access-point \ --file-system-id $EFS_FS_ID \ --posix-user Uid=1000,Gid=1000 \ --root-directory "Path=/bitnami/mongodb,CreationInfo={OwnerUid=1000,OwnerGid=1000,Permissions=777}" \ --region $AWS_REGION \ --query 'AccessPointId' \ --output text) -
Create the Persistent Volume (PV) using the EFS driver
and the access point you just created:
echo " apiVersion: v1 kind: PersistentVolume metadata: name: link-mongodb-pv spec: capacity: storage: 5Gi volumeMode: Filesystem accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Retain storageClassName: efs-sc csi: driver: efs.csi.aws.com volumeHandle: $EFS_FS_ID::$EFS_AP_MONGODB " | kubectl apply -f - -
Create the Persistent Volume Claim (PVC) and bind it to the PV:
echo " apiVersion: v1 kind: PersistentVolumeClaim metadata: name: link-mongodb-pvc spec: accessModes: - ReadWriteMany storageClassName: efs-sc volumeName: link-mongodb-pv resources: requests: storage: 5Gi " | kubectl apply -f - -
Verify that the PVC was created and successfully bound to the PV:
kubectl get pvc link-mongodb-pvcExample output:Name STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE link-mongodb-pvc Bound link-mongodb-pv 5Gi RWX efs-sc <unset> 20s