apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: grafana
  name: grafana
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: grafana
  template:
    metadata:
      labels:
        app.kubernetes.io/name: grafana
    spec:
      containers:
      - image: grafana/grafana:6.7.1
        name: grafana
        ports:
        - containerPort: 3000
          name: http
        env:
          - name: GF_DEFAULT_INSTANCE_NAME
            value: "grafana"
          - name: GF_USERS_ALLOW_SIGN_UP
            value: "False"
          - name: GF_ALERTING_ENABLED
            value: "False"
          - name: GF_METRICS_ENABLED
            value: "True"
          - name: GF_SERVER_DOMAIN
            valueFrom:
              secretKeyRef:
                name: grafana-config
                key: server-domain
          - name: GF_SERVER_ROOT_URL
            value: https://$(GF_SERVER_DOMAIN)
          - name: GF_SECURITY_ADMIN_USER
            valueFrom:
              secretKeyRef:
                name: grafana-config
                key: admin-user
          - name: GF_SECURITY_ADMIN_PASSWORD
            valueFrom:
              secretKeyRef:
                name: grafana-config
                key: admin-password
          - name: GF_DATABASE_SSL_MODE
            valueFrom:
              secretKeyRef:
                name: grafana-config
                key: db-ssl
          - name: GF_DATABASE_TYPE
            valueFrom:
              secretKeyRef:
                name: grafana-config
                key: db-type
          - name: GF_DATABASE_NAME
            valueFrom:
              secretKeyRef:
                name: grafana-config
                key: db-name
          - name: GF_DATABASE_USER
            value: $(GF_DATABASE_NAME)
          - name: GF_DATABASE_HOST
            valueFrom:
              secretKeyRef:
                name: grafana-config
                key: db-host
          - name: GF_DATABASE_PASSWORD
            valueFrom:
              secretKeyRef:
                name: grafana-config
                key: db-pass
          - name: GF_DATABASE_MAX_IDLE_CONN
            value: "2"
          - name: GF_DATABASE_MAX_OPEN_CONN
            value: "8"
          - name: GF_DATABASE_CONN_MAX_LIFETIME
            value: "1800"
          - name: GF_INSTALL_PLUGINS
            value: "fetzerch-sunandmoon-datasource,grafana-piechart-panel,grafana-simple-json-datasource,raintank-worldping-app"
        readinessProbe:
          httpGet:
            path: /api/health
            port: http
        resources:
          requests:
            cpu: 25m
            memory: 64Mi
        volumeMounts:
        - mountPath: /var/lib/grafana
          name: grafana-data
          readOnly: false
      nodeSelector:
        beta.kubernetes.io/os: linux
      securityContext:
        runAsNonRoot: true
        runAsUser: 65534
      volumes:
      - emptyDir: {}
        name: grafana-data
      dnsConfig:
        options:
        - name: ndots
          value: "1"
