apiVersion: apps/v1
kind: Deployment

metadata:
  name: grafana
  namespace: monitoring

spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana

  template:
    metadata:
      labels:
        app: grafana

    spec:
      containers:
        - name: grafana
          image: grafana/grafana:7.0.2
          resources:
            requests:
              cpu: 50m
              memory: 100Mi
            limits:
              cpu: 200m
              memory: 300Mi
          ports:
            - name: grafana
              containerPort: 3000
          readinessProbe:
            httpGet:
              path: /api/health
              port: 3000
          env:
            - name: GF_AUTH_BASIC_ENABLED
              value: "true"
            - name: GF_AUTH_ANONYMOUS_ENABLED
              value: "false"
            - name: GF_SECURITY_ADMIN_USER
              valueFrom:
                secretKeyRef:
                  name: grafana-secret
                  key: grafana-username
            - name: GF_SECURITY_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: grafana-secret
                  key: grafana-password
          volumeMounts:
            - name: grafana-config
              mountPath: /etc/grafana
            - name: grafana-datasources
              mountPath: /etc/grafana/provisioning/datasources
            - name: grafana-dashboards
              mountPath: /var/lib/grafana/dashboards
            - name: grafana-dashboardproviders
              mountPath: /etc/grafana/provisioning/dashboards/
            - name: grafana-storage
              mountPath: /var/lib/grafana
      volumes:
        - name: grafana-config
          configMap:
            name: grafana-ini
        - name: grafana-datasources
          configMap:
            name: grafana-datasources
        - name: grafana-dashboards
          configMap:
            name: grafana-dashboards
        - name: grafana-dashboardproviders
          configMap:
            name: grafana-dashboardproviders
        - name: grafana-storage
          persistentVolumeClaim:
            claimName: grafana
