Persisent Volume permission erros in MicroK8s

56 Views Asked by At

I am trying to deploy a Grafana instance in my Microk8s. As it is a test environment, I am continuously deleting and applying the manifests to deploy Grafana.

Then, I have encountered the problem that if I delete the deployment manifests, including the persistent volume claim manifest, when I deploy them again, the panels I have made have disappeared.

After investigating a bit, I created the following manifests:

A new storage class

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
 name: microk8s-persistent-data-storage-class
provisioner: microk8s.io/hostpath
reclaimPolicy: Retain
parameters:
 pvDir: /mnt/microk8s-persistent-data
volumeBindingMode: WaitForFirstConsumer

and a persistentVolumeClaim:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
 name: grafana-data
 namespace: backend
spec:
 storageClassName: microk8s-persistent-data-storage-class
 accessModes:
  - ReadWriteMany
 resources:
  requests:
   storage: 1Gi

If I deploy this together with the Grafana deployment, a persistent volume is automatically created where the panel information is stored. But if I delete the entire deployment again (including the persistent volume claim) and deploy everything again, I see in the Kubernetes that the persistent volume created before exists, but for this new deployment, another one has been created, so, even though the panels are not deleted, they are pointing to another persistent volume, I am left as before.

I have tried to create a Persistent volume and associate it with the persistent volume claim:

persistentVolume:

apiVersion: v1
kind: PersistentVolume
metadata:
 name: grafana-persistent-data
spec:
 capacity:
  storage: 1Gi
 accessModes:
  - ReadWriteMany
 persistentVolumeReclaimPolicy: Retain
 storageClassName: microk8s-persistent-data-storage-class
 volumeMode: Filesystem
 hostPath:
  path: /mnt/microk8s-persistent-data/grafana

leaving the PersistentVolumeClaim as follows:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
 name: grafana-data
 namespace: moneeda-backend
spec:
 storageClassName: microk8s-persistent-data-storage-class
 volumeName: grafana-persistent-data
 accessModes:
  - ReadWriteMany
 resources:
  requests:
   storage: 1Gi

In Microk8s I see that everything is configured correctly but when deploying Grafana, it gives me the following error:

GF_PATHS_DATA='/var/lib/grafana' is not writable.
You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied

I don't know what I'm doing wrong, or if there is something about the Microk8s configuration that I'm not doing... Does anyone have any ideas?

0

There are 0 best solutions below