
When you are dynamically provisioning PVC you don’t need to create PV at all. Kubernetes will auto create it
storageClass you have in eksctlkubectl get storageclass

Since, gp2 is listed you can directly use it as storageClass
pvc fileapiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: aws-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: gp2
kubectl apply -f aws-pvc.yml
deployment.yml to use aws-pvc.ymlapiVersion: apps/v1
kind: Deployment
metadata:
name: mongo-deployment
spec:
selector:
matchLabels:
app: mongo-pod
template:
metadata:
labels:
app: mongo-pod
spec:
containers:
- name: mongo-pod
image: mongo:latest
command: ["mongod","--bind_ip_all"] # runs db server
ports:
- containerPort: 27017
volumeMounts: # mongodb data at /data/db will persist outside this container at volume nfs-volume
- name: aws-volume
mountPath: /data/db # where mongo stores its database files
volumes:
- name: aws-volume
persistentVolumeClaim:
claimName: aws-pvc # attach this pvc
kubectl apply -f deployment.yml
pvc needs to be associated with pv . AWS may be taking time to create block storage pv and automatically provision it to pvcpv creation by following commandkubectl describe pvc aws-pvc
Without it, dynamic provisioning will never succeed.