apiVersion: v1
kind: Namespace
metadata:
  name: jellystack
---
# =========================
# PROWLARR
# =========================
apiVersion: apps/v1
kind: Deployment
metadata:
  name: prowlarr
  namespace: jellystack
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prowlarr
  template:
    metadata:
      labels:
        app: prowlarr
    spec:
      containers:
        - name: prowlarr
          image: lscr.io/linuxserver/prowlarr:latest
          ports:
            - containerPort: 9696
              name: http
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: "Europe/Paris"
          volumeMounts:
            - name: cfg
              mountPath: /config
      volumes:
        - name: cfg
          hostPath:
            path: /data/arr/config/prowlarr
            type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
  name: prowlarr
  namespace: jellystack
spec:
  selector:
    app: prowlarr
  ports:
    - name: http
      port: 9696
      targetPort: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: prowlarr
  namespace: jellystack
spec:
  ingressClassName: traefik
  rules:
    - host: prowlarr.delmar.bzh
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: prowlarr
                port:
                  number: 9696
---
# =========================
# DOWNLOADER
# =========================
apiVersion: apps/v1
kind: Deployment
metadata:
  name: downloader
  namespace: jellystack
spec:
  replicas: 1
  selector:
    matchLabels:
      app: downloader
  template:
    metadata:
      labels:
        app: downloader
    spec:
      containers:
        - name: downloader
          image: lscr.io/linuxserver/downloader:latest
          ports:
            - containerPort: 8080
              name: webui
            - containerPort: 6881
              name: bt-tcp
              protocol: TCP
            - containerPort: 6881
              name: bt-udp
              protocol: UDP
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: "Europe/Paris"
            - name: WEBUI_PORT
              value: "8080"
          volumeMounts:
            - name: cfg
              mountPath: /config
            - name: dl
              mountPath: /downloads
            - name: dl-inc
              mountPath: /incomplete
      volumes:
        - name: cfg
          hostPath:
            path: /data/arr/config/downloader
            type: DirectoryOrCreate
        - name: dl
          hostPath:
            path: /data/arr/downloads
            type: DirectoryOrCreate
        - name: dl-inc
          hostPath:
            path: /data/arr/incomplete
---
apiVersion: v1
kind: Service
metadata:
  name: downloader
  namespace: jellystack
spec:
  selector:
    app: downloader
  ports:
    - name: webui
      port: 8080
      targetPort: webui
---
# Expose P2P ports (forward from router to node IP)
apiVersion: v1
kind: Service
metadata:
  name: downloader-p2p
  namespace: jellystack
spec:
  type: NodePort
  selector:
    app: downloader
  ports:
    - name: bt-tcp
      port: 6881
      targetPort: bt-tcp
      nodePort: 31681
      protocol: TCP
    - name: bt-udp
      port: 6881
      targetPort: bt-udp
      nodePort: 31682
      protocol: UDP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: downloader
  namespace: jellystack
spec:
  ingressClassName: traefik
  rules:
    - host: downloader.delmar.bzh
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: downloader
                port:
                  number: 8080
---
# =========================
# SONARR
# =========================
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sonarr
  namespace: jellystack
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sonarr
  template:
    metadata:
      labels:
        app: sonarr
    spec:
      containers:
        - name: sonarr
          image: lscr.io/linuxserver/sonarr:latest
          ports:
            - containerPort: 8989
              name: http
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: "Europe/Paris"
          volumeMounts:
            - name: cfg
              mountPath: /config
            - name: dl
              mountPath: /downloads
            - name: lib
              mountPath: /media
      volumes:
        - name: cfg
          hostPath:
            path: /data/arr/config/sonarr
            type: DirectoryOrCreate
        - name: dl
          hostPath:
            path: /data/arr/downloads
            type: DirectoryOrCreate
        - name: lib
          hostPath:
            path: /data/arr/media
            type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
  name: sonarr
  namespace: jellystack
spec:
  selector:
    app: sonarr
  ports:
    - name: http
      port: 8989
      targetPort: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: sonarr
  namespace: jellystack
spec:
  ingressClassName: traefik
  rules:
    - host: sonarr.delmar.bzh
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: sonarr
                port:
                  number: 8989
---
# =========================
# RADARR
# =========================
apiVersion: apps/v1
kind: Deployment
metadata:
  name: radarr
  namespace: jellystack
spec:
  replicas: 1
  selector:
    matchLabels:
      app: radarr
  template:
    metadata:
      labels:
        app: radarr
    spec:
      containers:
        - name: radarr
          image: lscr.io/linuxserver/radarr:latest
          ports:
            - containerPort: 7878
              name: http
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: "Europe/Paris"
          volumeMounts:
            - name: cfg
              mountPath: /config
            - name: dl
              mountPath: /downloads
            - name: lib
              mountPath: /media
      volumes:
        - name: cfg
          hostPath:
            path: /data/arr/config/radarr
            type: DirectoryOrCreate
        - name: dl
          hostPath:
            path: /data/arr/downloads
            type: DirectoryOrCreate
        - name: lib
          hostPath:
            path: /data/arr/media
            type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
  name: radarr
  namespace: jellystack
spec:
  selector:
    app: radarr
  ports:
    - name: http
      port: 7878
      targetPort: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: radarr
  namespace: jellystack
spec:
  ingressClassName: traefik
  rules:
    - host: radarr.delmar.bzh
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: radarr
                port:
                  number: 7878
---
# =========================
# BAZARR
# =========================
apiVersion: apps/v1
kind: Deployment
metadata:
  name: bazarr
  namespace: jellystack
spec:
  replicas: 1
  selector:
    matchLabels:
      app: bazarr
  template:
    metadata:
      labels:
        app: bazarr
    spec:
      containers:
        - name: bazarr
          image: lscr.io/linuxserver/bazarr:latest
          ports:
            - containerPort: 6767
              name: http
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: "Europe/Paris"
          volumeMounts:
            - name: cfg
              mountPath: /config
            - name: lib
              mountPath: /media
            - name: subs
              mountPath: /subtitles
      volumes:
        - name: cfg
          hostPath:
            path: /data/arr/config/bazarr
            type: DirectoryOrCreate
        - name: lib
          hostPath:
            path: /data/arr/media
            type: DirectoryOrCreate
        - name: subs
          hostPath:
            path: /data/arr/subtitles
            type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
  name: bazarr
  namespace: jellystack
spec:
  selector:
    app: bazarr
  ports:
    - name: http
      port: 6767
      targetPort: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: bazarr
  namespace: jellystack
spec:
  ingressClassName: traefik
  rules:
    - host: bazarr.delmar.bzh
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: bazarr
                port:
                  number: 6767
---
# =========================
# JELLYFIN
# =========================
apiVersion: apps/v1
kind: Deployment
metadata:
  name: jellyfin
  namespace: jellystack
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jellyfin
  template:
    metadata:
      labels:
        app: jellyfin
    spec:
      containers:
        - name: jellyfin
          image: lscr.io/linuxserver/jellyfin:latest
          ports:
            - containerPort: 8096
              name: http
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: "Europe/Paris"
          volumeMounts:
            - name: cfg
              mountPath: /config
            - name: lib
              mountPath: /media
      volumes:
        - name: cfg
          hostPath:
            path: /data/arr/config/jellyfin
            type: DirectoryOrCreate
        - name: lib
          hostPath:
            path: /data/arr/media
            type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
  name: jellyfin
  namespace: jellystack
spec:
  selector:
    app: jellyfin
  ports:
    - name: http
      port: 8096
      targetPort: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: jellyfin
  namespace: jellystack
spec:
  ingressClassName: traefik
  rules:
    - host: jellyfin.delmar.bzh
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: jellyfin
                port:
                  number: 8096
