Kubernetes local storageclass (kubernetes.io/no-provisioner) retain policy volume

2/25/2019

Persistent volume doesn't retain existing data when pod is deleted and deployed back.

Once pod is removed, mapped persistent volume status changed to Released. Later when the same pod redeployed we can't use the same existing PV since it's not in Available state.

As suggested in https://kubernetes.io/docs/concepts/storage/persistent-volumes/#retain,
I have tried deleting Released PV and created the same PV where status is Available and it Bound to recreated pod but old data missing.

How we can claim the same PV with old data when pod is deleted and created back?

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: local-storage
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: kubernetes.io/no-provisioner
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer

-------------------------------

apiVersion: v1
kind: PersistentVolume
metadata:
  name: app-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage
  local:
    path: /data
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: role
          operator: In
          values:
          - data
-- erdarun
kubernetes
persistent-volumes
storage-class-specifier

0 Answers