apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: grafana
  labels:
    app.kubernetes.io/name: grafana
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: grafana
  serviceName: grafana
  template:
    metadata:
      labels:
        app.kubernetes.io/name: grafana
    spec:
      containers:
        - env:
            - name: GF_SECURITY_ADMIN_USER
              valueFrom:
                secretKeyRef:
                  key: admin-user
                  name: grafana
            - name: GF_SECURITY_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: admin-password
                  name: grafana
          image: quay.io/cybozu/grafana:8.1.5.1
          imagePullPolicy: IfNotPresent
          livenessProbe:
            failureThreshold: 10
            httpGet:
              path: /api/health
              port: 3000
              scheme: HTTP
            initialDelaySeconds: 60
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 30
          name: grafana
          ports:
            - containerPort: 3000
              name: grafana
              protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /api/health
              port: 3000
              scheme: HTTP
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /etc/grafana/grafana.ini
              name: config
              subPath: grafana.ini
            - mountPath: /etc/grafana/ldap.toml
              name: ldap
              subPath: ldap.toml
            - mountPath: /var/lib/grafana
              name: storage
            - name: datasources-provider
              mountPath: /etc/grafana/provisioning/datasources
      priorityClassName: node-bound
      securityContext:
        runAsUser: 10000
      volumes:
        - configMap:
            defaultMode: 420
            name: grafana
          name: config
        - name: ldap
          secret:
            defaultMode: 420
            items:
              - key: ldap-toml
                path: ldap.toml
            secretName: grafana
        - name: datasources-provider
          configMap:
            name: grafana-datasources-provider
            items:
              - key: providers.yaml
                path: providers.yaml
  volumeClaimTemplates:
    - metadata:
        name: storage
      spec:
        accessModes: [ "ReadWriteOnce" ]
        storageClassName: topolvm-provisioner
        resources:
          requests:
            storage: 1Gi
