<p>Let's say that I have a pre-existing (retained) EBS volume that was created by a PVC/PV that has been deleted by mistake. This volume was created like this:</p>
<pre><code>---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: gp2-retain
parameters:
  fsType: ext4
  type: gp2
provisioner: kubernetes.io/aws-ebs
reclaimPolicy: Retain
allowVolumeExpansion: true
volumeBindingMode: Immediate
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app: prometheus
  name: prometheus-server
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi
  storageClassName: gp2-retain
  volumeMode: Filesystem
</code></pre>
<p>and was used by a pod created by a helm chart with</p>
<pre><code>helm install prometheus-current stable/prometheus server.persistentVolume.existingClaim=prometheus-server
</code></pre>
<p>So this EBS contains some files created by that pod that I want to keep. Now, we managed to delete the PVC/PV <strong>but the EBS volume was retained</strong> due to the <code>reclaimPolicy</code>.</p>
<p><strong>So I want to recreate the PersistingVolumeClaim and PersistentVolume in a way that points to this particular EBS volumeID <code>aws://eu-west-1/vol-xxxxx</code>.</strong> How can created a PVC without triggering the dynamic provisioning and create a new PV backed by a completely new EBS
volume?</p>

RubenLaguna
<p>You can &quot;adopt&quot; an existing EBS-volume into a new PVC/PV the key points are:</p>
<ul>
<li>Create a <code>PersistentVolume</code> with a <code>.metadata.name</code> of your choosing (like <code>vol-imported-prometheus-server</code> and a <code>.spec.awsElasticBlockStore.volumeID</code> equal to <code>aws://region/vol-xxxx</code>
<ul>
<li>If you specify the <code>volumeID</code> Kubernetes will not try to allocate a new EBS volume</li>
</ul>
</li>
<li>Create a <code>PersistentVolumeClaim</code> with <code>spec.volumeName</code> equal to the name of the PV in the previous step
<ul>
<li>If you specify the <code>volumeName</code> Kubernetes will bound the PVC to the existing PV instead of trying to dynamically provision a new PV based on the <code>StorageClass</code></li>
</ul>
</li>
</ul>
<p>Like this example:</p>
<pre><code>---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: vol-imported-prometheus-server
spec:
  accessModes:
  - ReadWriteOnce
  awsElasticBlockStore:
    fsType: ext4
    volumeID: aws://eu-west-1c/vol-xxxxx
  capacity:
    storage: 8Gi
  persistentVolumeReclaimPolicy: Retain
  storageClassName: gp2-retain
  volumeMode: Filesystem
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app: prometheus
  name: imported-prometheus-server
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi
  storageClassName: gp2-retain
  volumeMode: Filesystem
  volumeName: vol-imported-prometheus-server
</code></pre>
<p>If you <code>kubectl apply -f thatfile.yaml</code> you will end up with the desired PVC -&gt; PV -&gt; existing EBS volume.</p>
<pre><code>kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                   STORAGECLASS   REASON   AGE
vol-imported-prometheus-server             8Gi        RWO            Retain           Bound    prometheus/imported-prometheus-server   gp2-retain              15m

kubectl get pvc
NAME                         STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
imported-prometheus-server   Bound    vol-imported-prometheus-server             8Gi        RWO            gp2-retain     16m
</code></pre>
<p>And then you can use that PVC name in helm  like so:</p>
<pre><code>helm install prometheus-current stable/prometheus server.persistentVolume.existingClaim=imported-prometheus-server 
</code></pre>
<p>where <code>imported-prometheus-server</code> is the name of the PVC you just created.</p>
