apiVersion: v1
kind: Namespace
metadata:
  name: metabase
  labels:
    name: metabase
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: metabase
  namespace: metabase
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: metabase-data
  namespace: metabase
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: azure-disk-std-ssd-lrs
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: metabase-config
  namespace: metabase
data:
  MB_DB_TYPE: "postgres"
  MB_DB_DBNAME: "metabase"
  MB_DB_PORT: "5432"
  MB_DB_USER: "metabase"
  MB_DB_HOST: "metabase-postgres"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: metabase
  namespace: metabase
  labels:
    app: metabase
spec:
  replicas: 1
  selector:
    matchLabels:
      app: metabase
  template:
    metadata:
      labels:
        app: metabase
    spec:
      serviceAccountName: metabase
      containers:
      - name: metabase
        image: metabase/metabase:latest
        ports:
        - containerPort: 3000
          name: http
        env:
        - name: MB_DB_TYPE
          valueFrom:
            configMapKeyRef:
              name: metabase-config
              key: MB_DB_TYPE
        - name: MB_DB_DBNAME
          valueFrom:
            configMapKeyRef:
              name: metabase-config
              key: MB_DB_DBNAME
        - name: MB_DB_PORT
          valueFrom:
            configMapKeyRef:
              name: metabase-config
              key: MB_DB_PORT
        - name: MB_DB_USER
          valueFrom:
            configMapKeyRef:
              name: metabase-config
              key: MB_DB_USER
        - name: MB_DB_HOST
          valueFrom:
            configMapKeyRef:
              name: metabase-config
              key: MB_DB_HOST
        - name: MB_DB_PASS
          valueFrom:
            secretKeyRef:
              name: metabase-db-secret
              key: password
        volumeMounts:
        - name: metabase-data
          mountPath: /metabase-data
        resources:
          requests:
            memory: "512Mi"
            cpu: "250m"
          limits:
            memory: "1Gi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /api/health
            port: 3000
          initialDelaySeconds: 120
          periodSeconds: 30
        readinessProbe:
          httpGet:
            path: /api/health
            port: 3000
          initialDelaySeconds: 30
          periodSeconds: 10
      volumes:
      - name: metabase-data
        persistentVolumeClaim:
          claimName: metabase-data
---
apiVersion: v1
kind: Service
metadata:
  name: metabase
  namespace: metabase
  labels:
    app: metabase
spec:
  type: ClusterIP
  ports:
  - port: 3000
    targetPort: 3000
    protocol: TCP
    name: http
  selector:
    app: metabase
---
apiVersion: v1
kind: Secret
metadata:
  name: metabase-db-secret
  namespace: metabase
type: Opaque
data:
  password: bWV0YWJhc2VwYXNzd29yZA==  # metabasepassword in base64
