How to Deploy an existing EBS volume to EKS PVC?

10/25/2021

I have an existing ebs volume in AWS with data on it. I need to create a PVC in order to use it in my pods. Following this guide: https://medium.com/pablo-perez/launching-a-pod-with-an-existing-ebs-volume-mounted-in-k8s-7b5506fa7fa3

persistentvolume.yaml

kind: PersistentVolume
apiVersion: v1
metadata:
  name: jenkins-volume
  labels:
    type: amazonEBS
spec:
  capacity:
    storage: 60Gi
  accessModes:
    - ReadWriteOnce
  awsElasticBlockStore:
    volumeID: vol-011111111x
    fsType: ext4
[$]>kubectl describe pv
Name:            jenkins-volume
Labels:          type=amazonEBS
Annotations:     <none>
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:
Status:          Available
Claim:
Reclaim Policy:  Retain
Access Modes:    RWO
VolumeMode:      Filesystem
Capacity:        60Gi
Node Affinity:   <none>
Message:
Source:
    Type:       AWSElasticBlockStore (a Persistent Disk resource in AWS)
    VolumeID:   vol-011111111x
    FSType:     ext4
    Partition:  0
    ReadOnly:   false
Events:         <none>

persistentVolumeClaim.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-pvc-shared4
  namespace: jenkins
spec:
  storageClassName: gp2
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 60Gi
[$]>kubectl describe pvc jenkins-pvc-shared4 -n jenkins
Name:          jenkins-pvc-shared4
Namespace:     jenkins
StorageClass:  gp2
Status:        Pending
Volume:
Labels:        <none>
Annotations:   <none>
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode:    Filesystem
Mounted By:    <none>
Events:
  Type    Reason                Age                From                         Message
  ----    ------                ----               ----                         -------
  Normal  WaitForFirstConsumer  12s (x2 over 21s)  persistentvolume-controller  waiting for first consumer to be created before binding
[$]>kubectl get pvc jenkins-pvc-shared4 -n jenkins
NAME                  STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
jenkins-pvc-shared4   Pending                                      gp2            36s

Status is pending (waiting to the consumer to be attached) - but it should already be provisioned.

-- SimonSK
amazon-eks
kubernetes
kubernetes-pvc

4 Answers

10/25/2021

try fsType "xfs" instead of ext4

-- Reza Nasiri
Source: StackOverflow

10/26/2021

StorageClass is empty for your PV. According to your guide, you created storageClass "standard", so add to your PersistentVolume spec

storageClassName: standard

and also set it in persistentVolumeClaim instead of gp2

-- Artem Bolotov
Source: StackOverflow

10/31/2021

The right config should be:

[$]>cat persistentvolume2.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-name
spec:
  accessModes:
  - ReadWriteOnce
  awsElasticBlockStore:
    fsType: ext4
    volumeID: aws://eu-west-2a/vol-123456-ID
  capacity:
    storage: 60Gi
  persistentVolumeReclaimPolicy: Retain
  storageClassName: gp2

[$]>cat persistentVolumeClaim2.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: new-namespace
  labels:
    app.kubernetes.io/name: <app-name>
  name: pvc-name
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 60Gi
  storageClassName: gp2
  volumeName: pv-name
-- SimonSK
Source: StackOverflow

10/25/2021

The "waiting for consumer" message suggests that your StorageClass has its volumeBindingMode set to waitForFirstConsumer.

The default value for this setting is Immediate: as soon as you register a PVC, your volume provisioner would provision a new volume.

The waitForFirstConsumer on the other hand would wait for a Pod to request usage for said PVC, before the provisioning a volume.

The messages and behavior you're seeing here sound normal. You may create a Deployment mounting that volume, to confirm provisioning works as expected.

-- SYN
Source: StackOverflow