apiVersion: apps/v1
kind: Deployment
metadata:
  name: alist
spec:
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: alist
  replicas: 1
  template:
    metadata:
      labels:
        app: alist
    spec:
      imagePullSecrets:
        - name: regcred
      volumes:
        - name: config
          persistentVolumeClaim:
            claimName: configs-nfs
        - name: downloads
          persistentVolumeClaim:
            claimName: downloads-nfs
        - name: books
          persistentVolumeClaim:
            claimName: books-nfs
      containers:
        - name: alist
          # 3.44 to avoid virus from new release https://github.com/AlistGo/alist/releases/tag/v3.44.0
          image: mirror.gcr.io/xhofe/alist:v3.51.0-ffmpeg
          securityContext:
            runAsUser: 0
            runAsGroup: 0
            fsGroup: 0
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 5244
              name: web-port
              protocol: TCP
          env:
            - name: TZ
              value: Australia/Melbourne
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: UMASK
              value: "022"
          volumeMounts:
            - name: config
              subPath: alist
              mountPath: /opt/alist/data
            - name: downloads
              subPath: ftp
              mountPath: /ftp
            - name: downloads
              mountPath: /downloads
            - name: books
              mountPath: /books
          resources:
            requests:
              cpu: 400m
              memory: 512Mi
            limits:
              cpu: 1000m
              memory: 2Gi
---
apiVersion: v1
kind: Service
metadata:
  name: alist
  labels:
    app: alist
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: web-port
      protocol: TCP
  selector:
    app: alist

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: alist-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/proxy-body-size: 102400m
    nginx.ingress.kubernetes.io/whitelist-source-range: "192.168.1.0/24"
    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:
  tls:
  - hosts:
    - alist.junv.cc
    secretName: alist-tls
  rules:
  - host: alist.junv.cc
    http:
      paths:
      - backend:
          service:
            name: alist
            port:
              number: 80
        path: /
        pathType: Prefix
