0

I am using PV with EFS. I have created a PV and PVC. My PV goes back to released status after I delete my StatefulSets. When I delete and re-apply my StatefulSets, it does not get attached to the same PV, instead the PVC status shows pending. My question is how do I get my pods in StatefulSet rebound to the same PV?

[kubeXpress]# k get pv

NAME      CAPACITY   ACCESS MODES   RECLAIM POLICY   **STATUS**     CLAIM            STORAGECLASS   REASON    AGE

efsvol    1Mi        RWO            Retain           **Released**   default/efsvol   aws-efs                  10m

[kubeXpress]# k get pvc
efsvol    **Pending**                                       aws-efs        10m

[kubeXpress]# k get po
NAME                                        READY     STATUS    RESTARTS   AGE
web-0                                       0/1       **Pending**   0          4m

[kubeXpress]# k describe po web-0
Events:
Type     Reason            Age                From               Message
  ----     ------            ----               ----               -------
Warning  FailedScheduling  2m (x37 over 12m)  default-scheduler  pod has unbound PersistentVolumeClaims (repeated 6 times)
Artem Golenyaev
  • 253
  • 1
  • 7
sumanth
  • 27
  • 3

1 Answers1

1

It seems like you need to create a new PVC for a new Pod to use an existing PV.

If you delete PV.Spec.ClaimRef reference in PV settings, any new PVC with appropriate setup could use it. Or if you want to assign PV to the exact PVC, you can fill PV.Spec.ClaimRef with the name of PVC and then create PVC with that name.

Don't forget to use Retain policy for a PV to prevent deletion after it is released.

Example of PV:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0001
spec:
  capacity:
    storage: 1Gi
  accessModes:
  - ReadWriteOnce
  nfs:
    path: /tmp
    server: 172.17.0.2
  persistentVolumeReclaimPolicy: Retain            #Here is policy
  claimRef:                                        #Here is claim reference
    name: claim1
    namespace: default

Example of PVC:

apiVersion: "v1"
kind: "PersistentVolumeClaim"
metadata:
  name: "claim1"
spec:
  accessModes:
    - "ReadWriteOnce"
  resources:
    requests:
      storage: "1Gi"
  volumeName: "pv0001"
Artem Golenyaev
  • 253
  • 1
  • 7