image.png

When you are dynamically provisioning PVC you don’t need to create PV at all. Kubernetes will auto create it

Step 1 : Check the storageClass you have in eksctl

kubectl get storageclass

image.png

Since, gp2 is listed you can directly use it as storageClass

Step 2 : Create pvc file

apiVersion: v1 
kind: PersistentVolumeClaim 
metadata:
  name: aws-pvc 
spec:
  accessModes:
    - ReadWriteOnce 
  resources:
    requests:
      storage: 5Gi 
  storageClassName: gp2
kubectl apply -f aws-pvc.yml

Step 3 : Update deployment.yml to use aws-pvc.yml

apiVersion: 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
kubectl describe pvc aws-pvc

Step 4 : You need to install AWS ECS CSI Driver

Why you need the EBS CSI Driver

Without it, dynamic provisioning will never succeed.