apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: movie-stack
spec:
  resources:
    requests:
      storage: 1Gi
  accessModes:
    - ReadWriteMany
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: movie-stack

spec:
  replicas: 1
  selector:
    matchLabels:
      app: movie-stack
  template:
    metadata:
      labels:
        app: movie-stack
    spec:
      containers:
        # FlareSolverr 解决 CloudFlare 5秒盾
        - name: flaresolverr
          image: flaresolverr/flaresolverr
          imagePullPolicy: IfNotPresent
          ports:
            - name: flaresolver-web # 不能超过15个字
              containerPort: 8191
              protocol: TCP
          env:
            - name: TZ
              value: Asia/Shanghai

        # 资源索引器(BT)
        - name: prowlarr
          image: linuxserver/prowlarr
          imagePullPolicy: IfNotPresent
          ports:
            - name: prowlarr-web
              containerPort: 9696
              protocol: TCP
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: Asia/Shanghai
          volumeMounts:
            - name: movie-stack
              subPath: prowlarr
              mountPath: /config

        # 资源刮削器（电影）
        - name: radarr
          image: linuxserver/radarr
          imagePullPolicy: IfNotPresent
          ports:
            - name: radarr-web
              containerPort: 7878
              protocol: TCP
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: Asia/Shanghai
          volumeMounts:
            - name: movie-stack
              subPath: radarr
              mountPath: /config
            - name: media
              mountPath: /media

        # 资源刮削器（电视剧&动漫）
        - name: sonarr
          image: linuxserver/sonarr
          imagePullPolicy: IfNotPresent
          ports:
            - name: sonarr-web
              containerPort: 8989
              protocol: TCP
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: Asia/Shanghai
          volumeMounts:
            - name: movie-stack
              subPath: sonarr
              mountPath: /config
            - name: media
              mountPath: /media

        # 资源聚合搜索
        - name: jellyseerr
          image: fallenbagel/jellyseerr
          imagePullPolicy: IfNotPresent
          ports:
            - name: jellyseerr-web
              containerPort: 5055
              protocol: TCP
          env:
            - name: TZ
              value: Asia/Shanghai
          volumeMounts:
            - name: movie-stack
              subPath: jellyseerr
              mountPath: /app/config

        # 播放器
        - name: jellyfin
          image: jellyfin/jellyfin
          imagePullPolicy: IfNotPresent
          ports:
            - name: jellyfin-web
              containerPort: 8096
              protocol: TCP
          env:
            - name: TZ
              value: Asia/Shanghai
            - name: HTTP_PROXY # 在这里设置代理
              value: http://192.168.1.2:7890
            - name: HTTPS_PROXY # 在这里设置代理
              value: http://192.168.1.2:7890
            - name: NO_PROXY
              value: "127.0.0.1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12,100.64.0.0/10,localhost,*.local,::ffff:0:0:0:0/1,::ffff:128:0:0:0/1,*.local,*.lan,*.homelab"
          securityContext:
            privileged: true
            runAsUser: 1000
            runAsGroup: 1000
          volumeMounts:
            - name: movie-stack
              subPath: jellyfin
              mountPath: /config
            - name: media
              mountPath: /media
            - name: device-dri # 挂载主机设备
              mountPath: /dev/dri

      volumes:
        - name: movie-stack
          persistentVolumeClaim:
            claimName: movie-stack
        - name: media # Use raw NFS directly
          nfs:
            path: /Media # NFS of Multimedia
            server: 192.168.1.88 # IP of my NAS
        - name: device-dri # 硬件解码，挂载集成显卡
          hostPath:
            path: /dev/dri

      dnsPolicy: ClusterFirst
      restartPolicy: Always
      securityContext:
        # 不能在这里统一设置UID和GID，原因是linuxserver的镜像不支持。
        # 如果统一设置，将导致linuxserver镜像里的应用无法启动
        supplementalGroups:
          - 44 # video
          - 103 # input
          - 106 # render

---
kind: Service
apiVersion: v1
metadata:
  name: movie-stack

spec:
  selector:
    app: movie-stack
  ports:
    - name: prowlarr-web
      port: 9696
      targetPort: 9696
      protocol: TCP
    - name: radarr-web
      port: 7878
      targetPort: 7878
      protocol: TCP
    - name: sonarr-web
      port: 8989
      targetPort: 8989
      protocol: TCP
    - name: jellyseerr-web
      port: 5055
      targetPort: 5055
      protocol: TCP
    - name: jellyfin-web
      port: 8096
      targetPort: 8096
      protocol: TCP
  type: LoadBalancer
  sessionAffinity: ClientIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: movie-stack

spec:
  rules:
    - host: prowlarr.homelab
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: movie-stack
                port:
                  name: prowlarr-web
    - host: radarr.homelab
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: movie-stack
                port:
                  name: radarr-web
    - host: sonarr.homelab
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: movie-stack
                port:
                  name: sonarr-web
    - host: jellyseerr.homelab
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: movie-stack
                port:
                  name: jellyseerr-web
    - host: jellyfin。home la b
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: movie-stack
                port:
                  name: jellyfin-web
