# Nginx Proxy Manager Data PersistentVolume
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nginx-proxy-manager-data-pvc
  namespace: home-apps
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: nfs-client
  resources:
    requests:
      storage: 3Gi
---

# Nginx Proxy Manager Letsencrypt PersistentVolume

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nginx-proxy-manager-letsencrypt-pvc
  namespace: home-apps
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: nfs-client
  resources:
    requests:
      storage: 2Gi
---

# Nginx Proxy Manager Service
apiVersion: v1
kind: Service
metadata:
  name: nginx-proxy-manager
  namespace: home-apps
spec:
  type: ClusterIP
  ports:
  - name: http
    port: 80
    targetPort: 80
  - name: admin
    port: 81
    targetPort: 81
  selector:
    app: nginx-proxy-manager
---

# Nginx Proxy Manager Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-proxy-manager
  namespace: home-apps
spec:
  selector:
    matchLabels:
      app: nginx-proxy-manager
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nginx-proxy-manager
    spec:
      nodeSelector:
        kubernetes.io/hostname: server-3
      securityContext:
        fsGroup: 0
        runAsUser: 0
        runAsNonRoot: false
      containers:
        - name: nginx-proxy-manager
          image: jc21/nginx-proxy-manager:latest
          ports:
            - containerPort: 80
            - containerPort: 443
            - containerPort: 81
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: "Australia/Melbourne"
            - name: DB_POSTGRES_HOST
              value: "192.168.1.2"
            - name: DB_POSTGRES_PORT
              value: "5432"
            - name: DB_POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: postgres-credential
                  key: username
            - name: DB_POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgres-credential
                  key: password
            - name: DB_POSTGRES_NAME
              value: "nginx_proxy_manager"
          volumeMounts:
            - name: data
              mountPath: /data
            - name: letsencrypt
              mountPath: /etc/letsencrypt
          resources:
            requests:
              cpu: 100m
              memory: 256Mi
            limits:
              cpu: 500m
              memory: 512Mi
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: nginx-proxy-manager-data-pvc
        - name: letsencrypt
          persistentVolumeClaim:
            claimName: nginx-proxy-manager-letsencrypt-pvc
---

# Wildcard Ingress for *.r.junv.cc (proxied services)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-proxy-manager-wildcard-ingress
  namespace: home-apps
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - "*.r.junv.cc"
    secretName: nginx-proxy-manager-wildcard-tls
  rules:
  - host: "*.r.junv.cc"
    http:
      paths:
      - backend:
          service:
            name: nginx-proxy-manager
            port:
              number: 80
        path: /
        pathType: Prefix
---

# Ingress for Admin Interface (port 81)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-proxy-manager-admin-ingress
  namespace: home-apps
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/auth-url: "https://pass.junv.cc/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: "https://pass.junv.cc/oauth2/start?rd=https://$host$escaped_request_uri"
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - npm-admin.junv.cc
    secretName: nginx-proxy-manager-admin-tls
  rules:
  - host: npm-admin.junv.cc
    http:
      paths:
      - backend:
          service:
            name: nginx-proxy-manager
            port:
              number: 81
        path: /
        pathType: Prefix
