apiVersion: v1
kind: Service
metadata:
  name: metabase
spec:
  ports:
  - port: 3000
    targetPort: web
  selector:
    app: metabase
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: metabase
spec:
  selector:
    matchLabels:
      app: metabase
  replicas: 1
  template:
    metadata:
      labels:
        app: metabase
    spec:
      containers:
      - name: metabase
        image: metabase/metabase
        securityContext:
          runAsUser: 0
        imagePullPolicy: IfNotPresent
        env:
          - name: MB_DB_TYPE
            value: postgres
          - name: MB_DB_DBNAME
            value: metabase
          - name: MB_DB_PORT
            value: "5432"
          - name: MB_DB_USER
            value: postgres
          - name: MB_DB_PASS
            valueFrom:
                secretKeyRef:
                  name: postgresql-credentials
                  key: password
          - name: MB_DB_HOST
            value: postgres-postgresql.db.svc.cluster.local
        ports:
          - containerPort: 3000
            name: web
        resources:
          requests:
            cpu: 200m
            memory: 256Mi
          limits:
            cpu: 800m
            memory: 1Gi
---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: metabase-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/auth-url: "https://id.home.toozhao.com/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: "https://id.home.toozhao.com/oauth2/start?rd=https%3A%2F%2F$host$request_uri"
spec:
  tls:
    - hosts:
        - metabase.home.toozhao.com
      secretName: metabase-tls
  rules:
    - host: metabase.home.toozhao.com
      http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: metabase
              port:
                number: 3000
