apiVersion: apps/v1
kind: Deployment
metadata:
  name: qbittorrent-main
  labels:
    app.kubernetes.io/controller: main
    app.kubernetes.io/instance: qbittorrent
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: qbittorrent
    helm.sh/chart: qbittorrent-4.6.2
  namespace: qbittorrent
spec:
  revisionHistoryLimit: 3
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app.kubernetes.io/controller: main
      app.kubernetes.io/name: qbittorrent
      app.kubernetes.io/instance: qbittorrent
  template:
    metadata:
      labels:
        app.kubernetes.io/controller: main
        app.kubernetes.io/instance: qbittorrent
        app.kubernetes.io/name: qbittorrent
    spec:
      enableServiceLinks: false
      serviceAccountName: default
      automountServiceAccountToken: true
      hostIPC: false
      hostNetwork: false
      hostPID: false
      dnsPolicy: ClusterFirst
      initContainers:
        - args:
            - -ec
            - |
              sysctl -w net.ipv4.ip_forward=1;
              sysctl -w net.ipv6.conf.all.disable_ipv6=1
          command:
            - /bin/sh
          image: busybox:1.37.0
          imagePullPolicy: IfNotPresent
          name: init-sysctl
          resources:
            requests:
              cpu: 10m
              memory: 128Mi
          securityContext:
            privileged: true
      containers:
        - env:
            - name: QBITTORRENT_HOST
              value: localhost
            - name: QBITTORRENT_PORT
              value: "8080"
            - name: EXPORTER_PORT
              value: "9022"
            - name: EXPORTER_LOG_LEVEL
              value: INFO
          image: esanchezm/prometheus-qbittorrent-exporter:v1.6.0
          imagePullPolicy: IfNotPresent
          name: exporter
          resources:
            requests:
              cpu: 10m
              memory: 64Mi
        - env:
            - name: VPN_SERVICE_PROVIDER
              value: protonvpn
            - name: VPN_TYPE
              value: wireguard
            - name: WIREGUARD_PRIVATE_KEY
              valueFrom:
                secretKeyRef:
                  key: private-key
                  name: qbittorrent-wireguard-conf
            - name: UPDATER_PROTONVPN_EMAIL
              valueFrom:
                secretKeyRef:
                  key: proton-email
                  name: qbittorrent-wireguard-conf
            - name: UPDATER_PROTONVPN_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: proton-password
                  name: qbittorrent-wireguard-conf
            - name: VPN_PORT_FORWARDING
              value: "on"
            - name: VPN_PORT_FORWARDING_UP_COMMAND
              value: /bin/sh -c "/gluetun/update.sh {{PORTS}}"
            - name: PORT_FORWARD_ONLY
              value: "on"
            - name: FIREWALL_OUTBOUND_SUBNETS
              value: 192.168.1.0/24,10.244.0.0/16
            - name: FIREWALL_INPUT_PORTS
              value: 8080,9022
            - name: DNS_UPSTREAM_RESOLVER_TYPE
              value: dot
          image: ghcr.io/qdm12/gluetun:v3.41.0@sha256:6b54856716d0de56e5bb00a77029b0adea57284cf5a466f23aad5979257d3045
          imagePullPolicy: IfNotPresent
          lifecycle:
            postStart:
              exec:
                command:
                  - /bin/sh
                  - -c
                  - (ip rule del table 51820; ip -6 rule del table 51820) || true
          livenessProbe:
            exec:
              command:
                - /gluetun-entrypoint
                - healthcheck
            failureThreshold: 5
            initialDelaySeconds: 30
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 15
          name: gluetun
          resources:
            limits:
              devic.es/tun: "1"
            requests:
              cpu: 10m
              devic.es/tun: "1"
              memory: 64Mi
          securityContext:
            capabilities:
              add:
                - NET_ADMIN
                - SYS_MODULE
            privileged: true
          volumeMounts:
            - mountPath: /gluetun/update.sh
              name: update-script
              subPath: update.sh
        - env:
            - name: TZ
              value: US/Central
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: UMASK_SET
              value: "002"
            - name: WEBUI_PORT
              value: "8080"
          image: ghcr.io/linuxserver/qbittorrent:5.1.4@sha256:5b09709bb0eff4edb551f5b30029952ab4d67aa0d5ca3526889124173bd78a9c
          imagePullPolicy: IfNotPresent
          name: qbittorrent
          resources:
            requests:
              cpu: 500m
              memory: 1Gi
          volumeMounts:
            - mountPath: /config/qBittorrent
              name: config-data
            - mountPath: /mnt/store
              name: storage
      volumes:
        - name: config-data
          persistentVolumeClaim:
            claimName: qbittorrent-config-data
        - name: storage
          persistentVolumeClaim:
            claimName: qbittorrent-nfs-storage
        - configMap:
            defaultMode: 493
            name: glutun-update-script
          name: update-script
