- Kubernetes 1.13+ (CSI 1.0).
- The aws-ebs-csi-driver installed.
- Created an Amazon EBS volume.
This example shows you how to create and consume a PersistentVolume from an existing EBS volume with static provisioning.
-
Edit the
PersistentVolumemanifest in pv.yaml to include yourvolumeHandleEBS volume ID andnodeSelectorTermszone value.The
StorageClasson thePersistentVolumeClaimandPersistentVolumemust match. If you have a default storage class, this means you must explicitly setspec.storageClassNameto""in the PVC manifest if the PV doesn't have aStorageClass.The
spec.volumeNamefield of the PVC must match the name of the PV for it to be selected.apiVersion: v1 kind: PersistentVolume metadata: name: test-pv spec: accessModes: - ReadWriteOnce capacity: storage: 5Gi csi: driver: ebs.csi.aws.com fsType: ext4 volumeHandle: {EBS volume ID} nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: topology.kubernetes.io/zone operator: In values: - {availability zone}
-
Deploy the provided pod on your cluster along with the
PersistentVolumeandPersistentVolumeClaim:$ kubectl apply -f manifests persistentvolumeclaim/ebs-claim created pod/app created persistentvolume/test-pv created
-
Validate the
PersistentVolumeClaimis bound to yourPersistentVolume.$ kubectl get pvc ebs-claim NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE ebs-claim Bound test-pv 5Gi RWO 53s
-
Validate the pod successfully wrote data to the statically provisioned volume:
$ kubectl exec app -- cat /data/out.txt Tue Feb 22 20:51:37 UTC 2022 ... -
Cleanup resources:
$ kubectl delete -f manifests persistentvolumeclaim "ebs-claim" deleted pod "app" deleted persistentvolume "test-pv" deleted