apiVersion: apps/v1
kind: Deployment
metadata:
  name: supertokens-db
  labels:
    app: flxn
    component: supertokens-db
spec:
  replicas: 1
  selector:
    matchLabels:
      app: flxn
      component: supertokens-db
  template:
    metadata:
      labels:
        app: flxn
        component: supertokens-db
    spec:
      containers:
      - name: postgres
        image: postgres:16-alpine
        ports:
        - containerPort: 5432
          name: postgres
          protocol: TCP
        env:
        - name: POSTGRES_USER
          value: "supertokens"
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: supertokens-secrets
              key: postgres_password
        - name: POSTGRES_DB
          value: "supertokens"
        - name: PGDATA
          value: "/var/lib/postgresql/data/pgdata"
        volumeMounts:
        - name: postgres-data
          mountPath: /var/lib/postgresql/data
        resources:
          requests:
            memory: "128Mi"
            cpu: "50m"
          limits:
            memory: "256Mi"
            cpu: "500m"
        livenessProbe:
          exec:
            command:
            - pg_isready
            - -U
            - supertokens
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          exec:
            command:
            - pg_isready
            - -U
            - supertokens
          initialDelaySeconds: 5
          periodSeconds: 5
      volumes:
      - name: postgres-data
        persistentVolumeClaim:
          claimName: supertokens-db-data
