apiVersion: apps/v1
kind: Deployment
metadata:
  name: files-ro-server
spec:
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: files-ro-server
  replicas: 1
  template:
    metadata:
      labels:
        app: files-ro-server
    spec:
      imagePullSecrets:
        - name: regcred
      volumes:
        - name: downloads
          persistentVolumeClaim:
            claimName: downloads-nfs
      containers:
        - name: files-ro-server
          image: caddy:2
          args: ["caddy", "file-server", "--listen", ":8080", "--root", "/www", "--browse"]
          securityContext:
            runAsUser: 1000
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
              name: web-port
              protocol: TCP
          env:
            - name: TZ
              value: Australia/Melbourne
          volumeMounts:
            - name: downloads
              mountPath: /www
          resources:
            requests:
              cpu: 100m
              memory: 126Mi
            limits:
              cpu: 400m
              memory: 512Mi
---
apiVersion: v1
kind: Service
metadata:
  name: files-ro-server
  labels:
    app: files-ro-server
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: web-port
      protocol: TCP
  selector:
    app: files-ro-server

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: files-ro-server-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"
spec:
  tls:
  - hosts:
    - ro.junv.cc
    secretName: ro-tls
  rules:
  - host: ro.junv.cc
    http:
      paths:
      - backend:
          service:
            name: files-ro-server
            port:
              number: 80
        path: /
        pathType: Prefix
