---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: pgweb
  namespace: postgres-clusters
spec:
  replicas: 1
  selector:
    matchLabels: &selector
      app: pgweb
  template:
    metadata:
      labels: *selector
    spec:
      containers:
        - name: pgweb
          image: sosedoff/pgweb
          command:
            - /usr/bin/pgweb
            - --bind=0.0.0.0
            - --sessions
            - --no-ssh
---
apiVersion: v1
kind: Service
metadata:
  name: pgweb
  namespace: postgres-clusters
spec:
  selector:
    app: pgweb
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081
---
apiVersion: codemowers.cloud/v1beta1
kind: OIDCMiddlewareClient
metadata:
  name: pgweb
spec:
  displayName: pgweb
  uri: 'https://pgweb.k-space.ee'
  allowedGroups:
    - k-space:floor
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: pgweb
  namespace: postgres-clusters
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/router.entrypoints: websecure
    traefik.ingress.kubernetes.io/router.tls: "true"
    external-dns.alpha.kubernetes.io/target: traefik.k-space.ee
    traefik.ingress.kubernetes.io/router.middlewares: postgres-clusters-pgweb@kubernetescrd
spec:
  rules:
    - host: pgweb.k-space.ee
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: pgweb
                port:
                  number: 8081
  tls:
    - hosts:
        - "*.k-space.ee"