Reputation: 311
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.
Upvotes: 2
Views: 8563
Reputation: 143
I was in a hurry first time I try to answer this because I was solving the same issue on my prod environment, and it seems I broke some rules about how to post here (receiving some "complains" and bad reputation (sigh)).
Although the awsElasticBlockStore could have solve the issue, it was deprecated since k8s v1.17. Now it is better to g by the CSI configuration.
In my case I needed to move the volume I had to a different AZ. I deployed the volume from a previous taken snapshot and once available I took note of its VolumeID.
For the PersistenVolume I used the followin config:
apiVersion: v1
kind: PersistentVolume
metadata:
name: <PV name>
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce <As I'm using EBS>
storageClassName: <yout StorageClass if you have one>
persistentVolumeReclaimPolicy: Retain
csi:
driver: <your csi driver>(in my case ebs.csi.aws.com)
volumeHandle: <VolumeID>
For the PersistenVolumeClaim I used the normal approach, nothing new to add:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: <PVC Name>
spec:
accessModes:
- ReadWriteOnce <Rememebr I'm using EBS>
resources:
requests:
storage: 5Gi
I had to delete the previous PV and PVC of my cluster and apply them again. The PV changed status to Bound once the PVC was deployed and the POD was running.
I follow the suggestions and examples on this offical AWS blog: https://aws.amazon.com/blogs/storage/persistent-storage-for-kubernetes/
Upvotes: 2
Reputation: 311
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
Upvotes: 3
Reputation: 21
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
Upvotes: 0
Reputation: 5041
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.
Upvotes: 1