I want to use same efs
as two static volumes.
For that, I have created the below two PersistentVolume Yamls:
Two PVs
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv001
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Delete
csi:
driver: efs.csi.aws.com
volumeHandle: fs-0fd788366150f8667.efs.us-east-1.amazonaws.com
volumeAttributes:
path: "/logs"
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv002
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Delete
csi:
driver: efs.csi.aws.com
volumeHandle: fs-0fd788366150f8667.efs.us-east-1.amazonaws.com
volumeAttributes:
path: "/data"
Two PVCs
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc001
spec:
resources:
requests:
storage: 3Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc002
spec:
resources:
requests:
storage: 6Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
replicas: 3
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
containers:
- image: nginx
name: nginx-cont
volumeMounts:
- name: logs
mountPath: /usr/share/nginx/html
- name: data
mountPath: /var/www/html
volumes:
- name: logs
persistentVolumeClaim:
claimName: pvc001
- name: data
persistentVolumeClaim:
claimName: pvc002
However, this is throwing below error:
Unable to attach or mount volumes: unmounted volumes=[logs], unattached volumes=[], failed to process volumes=[logs]:
I usually do this a little different. I create the pv:
Then I create the pvc:
And then I use it like this (just as an example):
Inside the application then something like this:
More info: https://aws.amazon.com/blogs/storage/persistent-storage-for-kubernetes/