2

I have a EKS cluster in AWS, which I manage using eksctl and kubectl in EC2. I am trying to create a persistent volume to bind it to multiple pods. I have created an EBS volume (gp2, 5GB) in region us-east-1 for this purpose. My manifests are like below;

storage-class.yml

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: ebsgp2
parameters:
  fsType: ext4
  type: gp2
provisioner: kubernetes.io/aws-ebs
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer
allowedTopologies:
- matchLabelExpressions:
  - key: topology.kubernetes.io/region
    values:
    - us-east-1
  - key: topology.kubernetes.io/zone
    values:
    - us-east-1a
    - us-east-1b
    - us-east-1c

pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: aws-pv
  labels:
    topology.kubernetes.io/region: us-east-1
    topology.kubernetes.io/zone: us-east-1a
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 5Gi
  persistentVolumeReclaimPolicy: Retain
  volumeMode: Filesystem
  csi:
    driver: ebs.csi.aws.com
    fsType: ext4
    volumeHandle: vol-XXXXXXXXXXXXXXXXX

pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ebs-claim
  namespace: namespace1
  labels:
    topology.kubernetes.io/region: us-east-1
    topology.kubernetes.io/zone: us-east-1a
spec:
  volumeName: aws-pv
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: ebsgp2

I requested the persistent volume claim using the command;

kubectl apply -f pvc.yaml

Then I listed PV and PVC with the commands below;

kubectl get pv
kubectl get pvc -n namespace1

PV got created;

NAME     CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
aws-pv   5Gi        RWO            Retain           Available                                   27m

And I could see the status of PVC as pending;

NAME        STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
ebs-claim   Pending   aws-pv   0                         ebsgp2         20s

kubectl get sc showed below output;

NAME            PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
ebsgp2          kubernetes.io/aws-ebs   Retain          WaitForFirstConsumer   true                   8m53s
gp2 (default)   kubernetes.io/aws-ebs   Delete          WaitForFirstConsumer   false                  3h23m

To investigate, I described the PVC using command kubectl describe pvc -n namespace1 ebs-claim and found the output like below;

kubectl describe pvc -n namespace1 ebs-claim
Name:          ebs-claim
Namespace:     namespace1
StorageClass:  ebsgp2
Status:        Pending
Volume:        aws-pv
Labels:        topology.kubernetes.io/region=us-east-1
               topology.kubernetes.io/zone=us-east-1a
Annotations:   <none>
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      0
Access Modes:
VolumeMode:    Filesystem
Used By:       <none>
Events:
  Type     Reason          Age                 From                         Message
  ----     ------          ----                ----                         -------
  Warning  VolumeMismatch  30s (x62 over 15m)  persistentvolume-controller  Cannot bind to requested volume "aws-pv": storageClassName does not match

Could somebody please tell me why its is happening? Thank you.

Reference;

Sibtain
  • 1,436
  • 21
  • 39
Alfred
  • 21,058
  • 61
  • 167
  • 249
  • 1
    please show the output of `kubectl get sc` – The Fool Mar 03 '23 at 09:30
  • @TheFool added the same to question, thanks. – Alfred Mar 03 '23 at 09:42
  • @Alfred have you created Storage class before you apply Persistent Volume Claim? – Richard Rublev Mar 03 '23 at 10:45
  • 1
    @RichardRublev yes, before I applied PVC. Thanks. – Alfred Mar 03 '23 at 10:55
  • By the looks of it, you are using [Dynamic provisioning](https://kubernetes.io/docs/concepts/storage/dynamic-provisioning/) which means you don't actually need to create a PV object. Skip the PV and try using storage class and PVC only instead. – Sibtain Mar 03 '23 at 12:26
  • Alternatively, the PV which is bound to a PVC both need to use the same `StorageClass`, currently you haven't defined a storage class with the PV – Sibtain Mar 03 '23 at 12:28

1 Answers1

0

You need to add 'storageClassName' under 'spec' for 'PV' as well. If you don't specify your 'storageClassName', it will use default which is probably the reason why you are having this issue since PV and PVC 'storageClassName' does not match.

https://kubernetes.io/docs/concepts/storage/persistent-volumes/#reserving-a-persistentvolume

iceveda06
  • 601
  • 8
  • 21