<p>I want to maintain a list of all PVs that have been created so far in the k8s cluster. So suppose I created 5 PVs and then deleted 2 of them. But I still want to know what were the names of the 5 PVs to start with? Is there some way to do that in kubernetes?</p>
<p>I was thinking of maintaining that list in a configmap or a CR but then if someone deletes the configmap/CR, we lose all data. Is having a database containing all those entries my only option?</p>

codego123
<p>Maintaining the list in a Custom Resource would be the most &quot;kubernetes-way&quot; to do it, as you mentioned. If you have a backup mechanism set up which can backup CRs as well (e.g. velero)</p>
<p>But if you want to store it outside the cluster, the simplest way would be to right a kubernetes CronJob which periodically gets the PVs and stores that data in an external storage. That way you can have several options to store it in S3, Git, any database.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: batch/v1
kind: CronJob
metadata:
  name: pv-list
spec:
  schedule: &quot;0 * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: busybox
            image: busybox # Your image containing the required tools
            imagePullPolicy: IfNotPresent
            command:
            - /bin/sh
            - -c
            - kubectl get pvs &gt; pvlist.txt
#e.g.       - aws s3 cp pvlist.txt s3://mybucket/pvlist.txt 
          restartPolicy: OnFailure
</code></pre>
