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.) 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.
# provides storage for grafana
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: grafana-pvc
labels:
app: grafana
spec:
storageClassName: nfs
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
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