apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: grafana
  namespace: monitoring
spec:
  serviceName: grafana
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: grafana
  volumeClaimTemplates:
    - metadata:
        name: grafana-data
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 100Gi
  template:
    spec:      
       # To get storage working. See https://stackoverflow.com/questions/60727107/how-can-i-give-grafana-user-appropriate-permission-so-that-it-can-start-successf
      securityContext:
        runAsUser: 0
        fsGroup: 0
      containers:
        - image: grafana/grafana
          name: grafana
          ports:
            - containerPort: 3000
              protocol: TCP
          resources:
            limits:
              cpu: 500m
              memory: 2500Mi
            requests:
              cpu: 100m
              memory: 100Mi
          volumeMounts:
            - mountPath: /var/lib/grafana
              name: grafana-data
      restartPolicy: Always