YosefMac
YosefMac

Reputation: 180

Bound a PVC with status Released

let me put you in context. I got pod with a configuration that looks close to this:

spec:
  nodeSets:
  - name: default
    count: 3
    volumeClaimTemplates:
    - metadata:
        name: elasticsearch-data
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 5Gi
        storageClassName: repd-ssd-xfs

I also have my StorageClass

apiVersion: ...
kind: StorageClass
metadata:
  name: repd-ssd-xfs
parameters:
  type: pd-ssd
  fsType: xfs
  replication-type: regional-pd
  zones: us-central1-a, us-central1-b, us-central1-f
reclaimPolicy: Retain
volumeBindingMode: Immediate

I delete the namespace of the pod and then apply again and I notice that the pvc that my pod was using change and bound to a new pvc, the last pvc used by the pod is in state released. My question is that Is there any way to specify to the pod to use my old pvc? The StorageClass policy is Retain but that means that I can still using pvc with status released?

Upvotes: 0

Views: 4976

Answers (2)

Serhii
Serhii

Reputation: 4471

In addition to the answer provided by @shashank tyagi.

Have a look at the documentation Persistent Volumes and at the section Retain you can find:

When the PersistentVolumeClaim is deleted, the PersistentVolume still exists and the volume is considered “released”. But it is not yet available for another claim because the previous claimant’s data remains on the volume. An administrator can manually reclaim the volume with the following steps.

  • Delete the PersistentVolume. The associated storage asset in external infrastructure (such as an AWS EBS, GCE PD, Azure Disk, or Cinder volume) still exists after the PV is deleted.
  • Manually clean up the data on the associated storage asset accordingly.
  • Manually delete the associated storage asset, or if you want to reuse the same storage asset, create a new PersistentVolume with the
    storage asset definition.

It could be helpful to check the documentation Persistent volumes with Persistent Disks and this example How to set ReclaimPolicy for PersistentVolumeClaim.

UPDATE Have a look at the article Persistent Volume Claim for StatefulSet.

Upvotes: 1

shashank tyagi
shashank tyagi

Reputation: 554

You can explicitly specify the persistent volume claim name in the pod spec if it's a deployment or a standalone pod like the code below:

 volumes:
  - name: task-pv-storage
     persistentVolumeClaim:
       claimName: task-pv-claim

However, if it's a StatefulSet, it will automatically attach to the same PVC every time the pod restarts. Hope this helps.

Upvotes: 1

Related Questions