# NFS Subdir Provisioner auto reclaim PV after restart

**URL:** <https://discuss.kubernetes.io/t/nfs-subdir-provisioner-auto-reclaim-pv-after-restart/29195>\
**Category:** microk8s\
**Created:** [July 29, 2024, 7:14am UTC](https://discuss.kubernetes.io/t/nfs-subdir-provisioner-auto-reclaim-pv-after-restart/29195 "2024-07-29T07:14:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andr3as](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@Andr3as](https://discuss.kubernetes.io/u/Andr3as)\
**Post date:** [July 29, 2024, 7:14am UTC](https://discuss.kubernetes.io/t/nfs-subdir-provisioner-auto-reclaim-pv-after-restart/29195/1 "2024-07-29T07:14:57Z")

</div>

In the last weeks I used microk8s to create a cluster on some raspberryPis. After setting ist up with Longhorn and some monitoring applications like Grafana, Prometheus etc., I wanted to switch to dynamic volume provision. So I started an NFS Server and installed the NFS Provisioner ([GitHub - kubernetes-sigs/nfs-subdir-external-provisioner: Dynamic sub-dir volume provisioner on a remote NFS server.](https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner)) into the cluster. My goal was to achieve that after pod restarts the volumes on the nfs Server automatically get attached to the new pod. So I set the reclaimPolicy on Retain and used the same Labels in PVC and Deployment, but now every time the NFS Provider creates a new Volume on the Server instead of using the old. I would appreciate your help and here my code thank you.

```auto
# provides storage for grafana

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana-pvc
  labels:
    app: grafana
spec:
  storageClassName: nfs
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

```

```auto
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      name: grafana
      labels:
        app: grafana
    spec:
      securityContext:
        fsGroup: 472
        runAsUser: 472
      containers:
        - name: grafana
          image: grafana/grafana:latest
          ports:
            - name: grafana
              containerPort: 3000
          resources:
            limits:
              memory: "1Gi"
              cpu: "1000m"
            requests:
              memory: "500Mi"
              cpu: "500m"
          volumeMounts:
            - mountPath: /var/lib/grafana
              name: grafana-storage
            - mountPath: /etc/grafana/provisioning/datasources
              name: grafana-datasources
              readOnly: false
      volumes:
        - name: grafana-storage
          persistentVolumeClaim:
            claimName: grafana-pvc
        - name: grafana-datasources
          configMap:
            defaultMode: 420
            name: grafana-datasources

```
