<p>env:</p>

<pre><code>kubernetes provider: gke
kubernetes version: v1.13.12-gke.25
grafana version: 6.6.2 (official image)
</code></pre>

<p>grafana deployment manifest:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      name: grafana
      labels:
        app: grafana
    spec:
      containers:
      - name: grafana
        image: grafana/grafana:6.6.2
        ports:
        - name: grafana
          containerPort: 3000
        # securityContext:
        #     runAsUser: 104
        #     allowPrivilegeEscalation: true
        resources:
          limits:
            memory: "1Gi"
            cpu: "500m"
          requests: 
            memory: "500Mi"
            cpu: "100m"
        volumeMounts:
          - mountPath: /var/lib/grafana
            name: grafana-storage
      volumes:
        - name: grafana-storage
          persistentVolumeClaim:
              claimName: grafana-pvc
</code></pre>

<p><strong>Problem</strong></p>

<p>when I deployed this grafana dashboard first time, its working fine. after sometime I restarted the pod to check whether volume mount is working or not. after restarting, I getting below error.</p>

<pre><code>mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
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/#migration-from-a-previous-version-of-the-docker-container-to-5-1-or-later
</code></pre>

<p>what I understand from this error, user could create these files. How can I give this user appropriate permission to start grafana successfully?</p>

Abu Hanifa
<p>I recreated your deployment with appropriate PVC and noticed that <code>grafana</code> pod was failing. </p>

<p>Output of command: <code>$ kubectl get pods -n monitoring</code></p>

<pre class="lang-sh prettyprint-override"><code>NAME READY STATUS RESTARTS AGE
grafana-6466cd95b5-4g95f 0/1 Error  2  65s
</code></pre>

<p>Further investigation pointed the same errors as yours: </p>

<pre class="lang-sh prettyprint-override"><code>mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
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/#migration-from-a-previous-version-of-the-docker-container-to-5-1-or-later
</code></pre>

<p>This error showed on first creation of a pod and the deployment. There was no need to recreate any pods.</p>

<p>What I did to make it work was to edit your deployment: </p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      name: grafana
      labels:
        app: grafana
    spec:
      securityContext:
          runAsUser: 472
          fsGroup: 472
      containers:
      - name: grafana
        image: grafana/grafana:6.6.2
        ports:
        - name: grafana
          containerPort: 3000
        resources:
          limits:
            memory: "1Gi"
            cpu: "500m"
          requests:
            memory: "500Mi"
            cpu: "100m"
        volumeMounts:
          - mountPath: /var/lib/grafana
            name: grafana-storage
      volumes:
        - name: grafana-storage
          persistentVolumeClaim:
              claimName: grafana-pvc
</code></pre>

<p>Please take a specific look on part: </p>

<pre class="lang-yaml prettyprint-override"><code>      securityContext:
          runAsUser: 472
          fsGroup: 472
</code></pre>

<p>It is a setting described in official documentation: <a href="https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod" rel="noreferrer">Kubernetes.io: set the security context for a pod</a></p>

<p>Please take a look on this Github issue which is similar to yours and pointed me to solution that allowed pod to spawn correctly: </p>

<ul>
<li><a href="https://github.com/grafana/grafana-docker/issues/167" rel="noreferrer">https://github.com/grafana/grafana-docker/issues/167</a> </li>
</ul>

<p>Grafana had some major updates starting from version 5.1. Please take a look: <a href="https://grafana.com/docs/grafana/latest/installation/docker/#migrate-to-v5-1-or-later" rel="noreferrer">Grafana.com: Docs: Migrate to v5.1 or later</a></p>

<p>Please let me know if this helps. </p>
