apiVersion: v1
kind: Service
metadata:
  name: gphotos-uploader
  labels:
    run: gphotos-uploader
spec:
  ports:
    - name: http
      port: 80
      targetPort: 29070
  selector:
    run: gphotos-uploader
#  type: LoadBalancer
#status:
#  loadBalancer: {}
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: gphotos-uploader-photos
spec:
  capacity:
    storage: 10Ti
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain # Keep 4eva
  storageClassName: default
  mountOptions:
    - hard
    - nfsvers=3
  nfs:
    path: /mnt/DroboFS/Shares/Public/midjourney
    server: 10.42.42.10
  claimRef:
    name: gphotos-uploader-photos
    namespace: default
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: gphotos-uploader-photos
spec:
  storageClassName: standard
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Ti
status: {}
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: gphotos-uploader-config
spec:
  capacity:
    storage: 5Mi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain # Keep 4eva
  storageClassName: default
  mountOptions:
    - hard
    - nfsvers=3
  nfs:
    path: /mnt/DroboFS/Shares/Kubernetes/volumes/static/gphotos-uploader-config
    server: 10.42.42.10
  claimRef:
    name: gphotos-uploader-config
    namespace: default
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: gphotos-uploader-config
  annotations:
    nfs.io/storage-path: "gphotos-uploader-config"
spec:
  storageClassName: default
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Mi
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gphotos-uploader
spec:
  replicas: 1
  selector:
    matchLabels:
      run: gphotos-uploader
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        run: gphotos-uploader
    spec:
      terminationGracePeriodSeconds: 30
      containers:
        - image: rfgamaral/gphotos-uploader:amd64-latest
          imagePullPolicy: "Always"
          name: gphotos-uploader
          env:
            - name: GPU_SCHEDULE
              value: "*/30 * * * *"
            - name: TZ
              value: US/Michigan
          ports:
            - containerPort: 29070
          resources:
            limits:
              memory: "500Mi"
              cpu: "500m"
            requests:
              memory: "300Mi"
              cpu: "250m"
          volumeMounts:
            - mountPath: /config
              name: gphotos-uploader-config
            - mountPath: /photos
              name: gphotos-uploader-photos
      restartPolicy: Always
      volumes:
        - name: gphotos-uploader-config
          persistentVolumeClaim:
            claimName: gphotos-uploader-config
        - name: gphotos-uploader-photos
          persistentVolumeClaim:
            claimName: gphotos-uploader-photos
      dnsPolicy: "None"
      dnsConfig:
        nameservers:
          - 10.42.42.239
          - 10.42.42.1
        searches:
          - default.svc.cluster.local
          - svc.cluster.local 
          - cluster.local
        options:
          - name: ndots
            value: "2"
          - name: edns0
          - name: trust-ad
status: {}
---
# Hosting
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: gphotos-uploader-ingress
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    ## No basic auth for gphotos-uploader
    ## type of authentication
    #nginx.ingress.kubernetes.io/auth-type: basic
    ## name of the secret that contains the user/password definitions
    #nginx.ingress.kubernetes.io/auth-secret: basic-auth
    ## message to display with an appropriate context why the authentication is required
    #nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - Octoprint'
spec:
  tls:
  - hosts:
    - gphotos-uploader.monkeybox.org
    secretName: gphotos-uploader-tls
  rules:
  - host: gphotos-uploader.monkeybox.org
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: gphotos-uploader
            port:
              number: 80
