apiVersion: v1
kind: Service
metadata:
  name: couchpotato
  labels:
    run: couchpotato
spec:
  ports:
    - name: http
      port: 80
      targetPort: 5050
  selector:
    run: couchpotato
#  type: LoadBalancer
#status:
#  loadBalancer: {}
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: couchpotato-movies
spec:
  capacity:
    storage: 10Ti
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain # Keep 4eva
  storageClassName: default
  mountOptions:
    - hard
    - nfsvers=3
  nfs:
    path: /mnt/DroboFS/Shares/Public/media/movies
    server: 10.42.42.10
  claimRef:
    name: couchpotato-movies
    namespace: default
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: couchpotato-shared
spec:
  capacity:
    storage: 10Ti
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain # Keep 4eva
  storageClassName: default
  mountOptions:
    - hard
    - nfsvers=3
  nfs:
    path: /mnt/DroboFS/Shares/Public/
    server: 10.42.42.10
  claimRef:
    name: couchpotato-shared
    namespace: default
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: couchpotato-movies
spec:
  storageClassName: standard
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Ti
status: {}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: couchpotato-shared
spec:
  storageClassName: standard
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Ti
status: {}
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: couchpotato-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/couchpotato-config
    server: 10.42.42.10
  claimRef:
    name: couchpotato-config
    namespace: default
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: couchpotato-config
  annotations:
    nfs.io/storage-path: "couchpotato-config"
spec:
  storageClassName: default
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Mi
status: {}
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: couchpotato-downloads
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/couchpotato-downloads
    server: 10.42.42.10
  claimRef:
    name: couchpotato-downloads
    namespace: default
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: couchpotato-downloads
  annotations:
    nfs.io/storage-path: "couchpotato-downloads"
spec:
  storageClassName: default
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Mi
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: couchpotato
spec:
  replicas: 1
  selector:
    matchLabels:
      run: couchpotato
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        run: couchpotato
    spec:
      containers:
        - image: linuxserver/couchpotato
          imagePullPolicy: "Always"
          name: couchpotato
          env:
            - name: TZ
              value: US/Michigan
          ports:
            - containerPort: 5050
          resources: {}
          volumeMounts:
            - mountPath: /config
              name: couchpotato-config
            - mountPath: /downloads
              name: couchpotato-downloads
            - mountPath: /movies
              name: couchpotato-movies
            - mountPath: /shared
              name: couchpotato-shared
      restartPolicy: Always
      volumes:
        - name: couchpotato-config
          persistentVolumeClaim:
            claimName: couchpotato-config
        - name: couchpotato-downloads
          persistentVolumeClaim:
            claimName: couchpotato-downloads
        - name: couchpotato-movies
          persistentVolumeClaim:
            claimName: couchpotato-movies
        - name: couchpotato-shared
          persistentVolumeClaim:
            claimName: couchpotato-shared
      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: couchpotato-ingress
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    ## No basic auth for couchpotato
    ## 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:
    - couchpotato.monkeybox.org
    - movies.monkeybox.org
    secretName: couchpotato-tls
  rules:
  - host: couchpotato.monkeybox.org
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: couchpotato
            port:
              number: 80
  - host: movies.monkeybox.org
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: couchpotato
            port:
              number: 80
