---


apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  labels:
    app: grafana
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
    spec:
      containers:
        - image: grafana/grafana
          name: grafana
          imagePullPolicy: IfNotPresent
          ports:
            - name: grafana
              containerPort: 3000
              protocol: TCP
          volumeMounts:
            - name: grafana-datasources
              mountPath: /etc/grafana/provisioning/datasources
              readOnly: true
            - name: grafana-dashboards
              mountPath: /etc/grafana/provisioning/dashboards
              readOnly: true
            - name: grafana-data
              mountPath: /var/lib/grafana
      # Get around the fact that the mount is owned by root:root
      initContainers:
        - name: grafana-data-permission-fix
          image: debian:stretch-slim
          imagePullPolicy: IfNotPresent
          command: ["sh", "-c", "chown -R 472:472 /data"]
          volumeMounts:
          - name: grafana-data
            mountPath: /data
      volumes:
        - name: grafana-data
          hostPath:
            path: /var/lib/grafana
        - name: grafana-datasources
          configMap:
            name: grafana-provisioning-datasources
        - name: grafana-dashboards
          configMap:
            name: grafana-provisioning-dashboards
