apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: grafana-statefulset
  namespace: monitoring
spec:
  serviceName: "grafana-service"
  selector:
    matchLabels:
      app: grafana
  replicas: 1
  template:
    metadata:
      labels:
        component: "grafana-container"
        app: grafana
        k8s-app: grafana
        metrics: "true"
    spec:
      volumes:
        - name: grafana-dashboards-kubernetes
          configMap:
            name: grafana-dashboards-kubernetes
        - name: grafana-dashboards-prometheus
          configMap:
            name: grafana-dashboards-prometheus
        - name: grafana-dashboards-general
          configMap:
            name: grafana-dashboards-general
        - name: grafana-provisioning
          configMap:
            name: grafana-provisioning
        - name: grafana-datasources
          secret:
            secretName: grafana-datasources
      containers:
        - name: grafana
          image: grafana/grafana:7.2.0-beta2
          ports:
            - containerPort: 3000
              protocol: TCP
          volumeMounts:
            - mountPath: /var/lib/grafana
              name: grafana-storage
            - mountPath: /var/lib/grafana/dashboards/prometheus
              name: grafana-dashboards-prometheus
            - mountPath: /var/lib/grafana/dashboards/general
              name: grafana-dashboards-general
            - mountPath: /var/lib/grafana/dashboards/kubernetes
              name: grafana-dashboards-kubernetes
            - mountPath: /etc/grafana/provisioning/dashboards/dashboards-kubernetes.yaml
              subPath: dashboards-kubernetes.yaml
              name: grafana-provisioning
            - mountPath: /etc/grafana/provisioning/dashboards/dashboards-prometheus.yaml
              subPath: dashboards-prometheus.yaml
              name: grafana-provisioning
            - mountPath: /etc/grafana/provisioning/dashboards/dashboards-general.yaml
              subPath: dashboards-general.yaml
              name: grafana-provisioning
            - mountPath: /etc/grafana/provisioning/datasources/datasources.yaml
              subPath: datasources.yaml
              name: grafana-datasources
            - mountPath: /etc/grafana/provisioning/plugins/plugins.yaml
              subPath: plugins.yaml
              name: grafana-provisioning
          env:
            - name: GF_SERVER_HTTP_PORT
              value: "3000"
            - name: GF_SECURITY_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: grafana-secret
                  key: ADMIN_PASSWORD
  volumeClaimTemplates:
    - metadata:
        name: grafana-storage
        labels:
          app: grafana
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 512Mi
