---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: plex
  namespace: "{{ .Release.Namespace }}"
  labels:
    app: plex
    io.kompose.service: plex
  annotations:
    applications.app.bytetrade.io/gpu-inject: "true"
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: plex
      io.kompose.service: plex
  template:
    metadata:
      labels:
        app: plex
        io.kompose.service: plex
        io.kompose.network/chrome-default: "true"
    spec:
      containers:
        - name: plex
          image: "{{ .Values.image }}"
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: "{{ .Values.timezone }}"
            - name: VERSION
              value: "docker"
            - name: NVIDIA_VISIBLE_DEVICES
              value: "all"
            - name: NVIDIA_DRIVER_CAPABILITIES
              value: "all"
          ports:
            - containerPort: 32400
              name: plex-web
          startupProbe:
            tcpSocket:
              port: 32400
            failureThreshold: 30
            periodSeconds: 10
          livenessProbe:
            httpGet:
              path: /identity
              port: 32400
            initialDelaySeconds: 10
            timeoutSeconds: 10
            periodSeconds: 30
            failureThreshold: 5
          resources:
            limits:
              cpu: "4"
              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
          hostPath:
            path: "{{ .Values.configPath }}"
            type: DirectoryOrCreate
        - name: media
          hostPath:
            path: "{{ .Values.mediaPath }}"
            type: Directory
        - name: transcode
          emptyDir:
            medium: Memory
            sizeLimit: "{{ .Values.transcodeSizeLimit }}"
      restartPolicy: Always

---
apiVersion: v1
kind: Service
metadata:
  name: plex
  namespace: "{{ .Release.Namespace }}"
  labels:
    io.kompose.service: plex
spec:
  ports:
    - name: plex-web
      port: 32400
      targetPort: 32400
  selector:
    io.kompose.service: plex
