apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  labels:
    app: grafana
spec:
  selector:
    matchLabels:
      app: grafana
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: grafana
    spec:
      containers:
        - name: grafana
          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: registry.homelab.dsb.dev/grafana/grafana:7.3.6
          livenessProbe:
            failureThreshold: 10
            httpGet:
              path: /api/health
              port: 3000
            initialDelaySeconds: 60
            timeoutSeconds: 30
          ports:
            - containerPort: 80
              name: service
              protocol: TCP
            - containerPort: 3000
              name: grafana
              protocol: TCP
          readinessProbe:
            httpGet:
              path: /api/health
              port: 3000
          volumeMounts:
            - mountPath: /etc/grafana/grafana.ini
              name: config
              subPath: grafana.ini
            - mountPath: /var/lib/grafana
              name: storage
      initContainers:
        - command:
            - chown
            - -R
            - 472:472
            - /var/lib/grafana
          image: registry.homelab.dsb.dev/library/busybox:1.31.1
          name: init-chown-data
          securityContext:
            runAsUser: 0
          volumeMounts:
            - mountPath: /var/lib/grafana
              name: storage
      securityContext:
        fsGroup: 472
        runAsGroup: 472
        runAsUser: 472
      volumes:
        - configMap:
            defaultMode: 420
            name: grafana
          name: config
        - name: storage
          persistentVolumeClaim:
            claimName: grafana
