apiVersion: v1
kind: Namespace
metadata:
  name: plex
---
apiVersion: v1
kind: REDACTED_APP_PASSWORD
metadata:
  name: plex-config-pv
spec:
  capacity:
    storage: 50Gi
  accessModes:
    - ReadWriteOnce
  storageClassName: local
  local:
    path: /var/olares/userdata/plex-config
  nodeAffinity:
    required:
      nodeSelectorTerms:
        - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
                - olares
  persistentVolumeReclaimPolicy: Retain
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: plex-config
  namespace: plex
spec:
  storageClassName: local
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 50Gi
  volumeName: plex-config-pv
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: plex
  namespace: plex
  labels:
    app: plex
    applications.app.bytetrade.io/name: plex
    applications.app.bytetrade.io/owner: vishinator
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: plex
  template:
    metadata:
      labels:
        app: plex
        applications.app.bytetrade.io/name: plex
        applications.app.bytetrade.io/owner: vishinator
        io.bytetrade.app: "true"
    spec:
      runtimeClassName: nvidia
      containers:
        - name: plex
          image: lscr.io/linuxserver/plex:latest
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: "America/Los_Angeles"
            - name: VERSION
              value: "docker"
            - name: NVIDIA_VISIBLE_DEVICES
              value: "all"
            - name: NVIDIA_DRIVER_CAPABILITIES
              value: "all"
          ports:
            - containerPort: 32400
              name: plex-web
          resources:
            limits:
              nvidia.com/gpu: "1"
              nvidia.com/gpumem: "4096"
              memory: "8Gi"
            requests:
              cpu: "500m"
              memory: "2Gi"
          volumeMounts:
            - name: config
              mountPath: /config
            - name: media
              mountPath: /media
              readOnly: true
            - name: transcode
              mountPath: /transcode
      volumes:
        - name: config
          persistentVolumeClaim:
            claimName: plex-config
        - name: media
          hostPath:
            path: /mnt/atlantis_media
        - name: transcode
          emptyDir:
            medium: Memory
            sizeLimit: 4Gi
---
apiVersion: v1
kind: Service
metadata:
  name: plex
  namespace: plex
spec:
  type: NodePort
  externalIPs:
    - 192.168.0.145
  selector:
    app: plex
  ports:
    - port: 32400
      targetPort: 32400
      nodePort: 32400
      name: plex-web
