File share in Azure File is deleted when PVC is deleted even when storage class has reclaimPolicy Retain
What happened: Created a pod with a PVC backed by a Azure File storage class with the reclaimPolicy: Retain. When I delete the PVC, the file share in Azure File is deleted What you expected to happen: During clean up, I delete the pod, then delete the PVC but I want to retain the files in the azure share that the storage account is attached to. How to reproduce it (as minimally and precisely as possible):
- Create a storage account as a file share
- Create a k8s storage class pointing to the storage account using provisioner: kubernetes.io/azure-file and reclaimPolicy: Retain
- Create a PVC that points to the storage class without a PV
- Create a pod with a volume claim to the PVC
- Write some files into the volume and Azure portal to see if it is there
- Delete the pod. The files should still be in the file share
- Delete the PVC. All files including the file share is gone Anything else we need to know?:
Environment:
- Kubernetes version (use
kubectl version): Kubernetes 1.16.10 - Size of cluster (how many worker nodes are in the cluster?)
- General description of workloads in the cluster (e.g. HTTP microservices, Java app, Ruby on Rails, machine learning, etc.)
- Others:
So by not defining a PV, the persistentVolumeReclaimPolicy option is not being propagated. I end up creating a PV and set a claim to the PVC even though the PVC creates a dynamic PV anyways.
Solution is to add a PV that links to the PVC with "persistentVolumeReclaimPolicy: Retain" option.