From 80321ac4a993b3575db627c5b7c0f0be6e1f1bec Mon Sep 17 00:00:00 2001 From: bart Date: Fri, 30 Oct 2026 10:08:18 +0100 Subject: [PATCH] feat(jackett): add jackett deployment, service, pvc and migration scripts --- README.md | 15 +++++ cleanup_old_jackett.sh | 57 ++++++++++++++++++ k8s/jackett/deployment.yaml | 99 ++++++++++++++++++++++++++++++ k8s/jackett/kustomization.yaml | 7 +++ k8s/jackett/pvc.yaml | 15 +++++ k8s/jackett/service.yaml | 17 ++++++ k8s/kustomization.yaml | 1 + migrate_jackett_to_cluster.sh | 106 +++++++++++++++++++++++++++++++++ 8 files changed, 317 insertions(+) create mode 100755 cleanup_old_jackett.sh create mode 100644 k8s/jackett/deployment.yaml create mode 100644 k8s/jackett/kustomization.yaml create mode 100644 k8s/jackett/pvc.yaml create mode 100644 k8s/jackett/service.yaml create mode 100755 migrate_jackett_to_cluster.sh diff --git a/README.md b/README.md index 588d333..13a5e73 100644 --- a/README.md +++ b/README.md @@ -83,3 +83,18 @@ De Soulseek daemon (`slskd`) draait als pod in de `htpc` namespace: # Oude host bestanden en service opruimen: ./cleanup_old_slskd.sh ``` + +### Jackett +De torrent indexer proxy (`jackett`) draait als pod in de `htpc` namespace: + +- **Dataopslag**: PersistentVolumeClaim `jackett-config` (10Gi, `local-path` op `/datadisk/infra/pv`), gemigreerd vanuit `/home/bart/.config/Jackett` via init-container (inclusief alle indexers en `ServerConfig.json`). +- **Mediaopslag**: HostPath `/datadisk` gemount op `/datadisk`. +- **Netwerk & Ingress**: Luistert op poort `9117` (ClusterIP + HostPort `9117`). De Apache reverse proxy routeert `https://thuus.bnhmeijer.nl/jackett/` naadloos door naar `127.0.0.1:9117`. +- **Migratie & Opruimen**: + ```bash + # Migratie uitvoeren (maakt backup in /storage/backups/, stopt host service, start pod): + ./migrate_jackett_to_cluster.sh + + # Oude host bestanden en service opruimen: + ./cleanup_old_jackett.sh + ``` diff --git a/cleanup_old_jackett.sh b/cleanup_old_jackett.sh new file mode 100755 index 0000000..2a58335 --- /dev/null +++ b/cleanup_old_jackett.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# ============================================================================== +# Opruimen van oude standalone Jackett installatie op vmserver (10.2.0.4) +# ============================================================================== +set -euo pipefail + +CLUSTER_HOST="10.2.0.4" +SSH_USER="bart" + +COLOR_GREEN="\033[0;32m" +COLOR_YELLOW="\033[1;33m" +COLOR_RED="\033[0;31m" +COLOR_BLUE="\033[0;34m" +COLOR_RESET="\033[0m" + +log_info() { echo -e "${COLOR_GREEN}[INFO]${COLOR_RESET} $1"; } +log_step() { echo -e "\n${COLOR_BLUE}==>${COLOR_RESET} ${COLOR_GREEN}$1${COLOR_RESET}"; } +log_warn() { echo -e "${COLOR_YELLOW}[WARN]${COLOR_RESET} $1"; } + +echo "========================================================================" +echo " OPRUIMEN OUDE STANDALONE JACKETT OP ${CLUSTER_HOST}" +echo "========================================================================" +echo "Dit stopt en verwijdert de oude standalone bestanden op ${CLUSTER_HOST}:" +echo " - /etc/systemd/system/jackett.service" +echo " - /opt/Jackett (oude binaries & updater)" +echo " - /home/bart/.config/Jackett (config is gemigreerd naar K8s PVC & backup in /storage/backups/)" +echo "========================================================================" +echo "" + +read -p "Weet je zeker dat je de oude standalone Jackett bestanden wilt verwijderen? (j/N): " -r CONFIRM +if [[ ! "$CONFIRM" =~ ^[jJyY]$ ]]; then + log_info "Opruimen geannuleerd." + exit 0 +fi + +log_step "Verwijderen van systemd service en programmabestanden op ${CLUSTER_HOST}..." +ssh -t "${SSH_USER}@${CLUSTER_HOST}" " + echo '--> Stoppen en uitschakelen van jackett.service...' + sudo systemctl stop jackett 2>/dev/null || true + sudo systemctl disable jackett 2>/dev/null || true + sudo rm -f /etc/systemd/system/jackett.service + sudo systemctl daemon-reload + sudo systemctl reset-failed 2>/dev/null || true + + echo '--> Verwijderen van /opt/Jackett...' + sudo rm -rf /opt/Jackett + + echo '--> Verwijderen van /home/bart/.config/Jackett...' + sudo rm -rf /home/bart/.config/Jackett + + echo '--> Opslagruimte controleren...' + df -h / /datadisk /storage +" + +echo "" +log_info "De oude standalone Jackett is succesvol opgeruimd!" +echo "Alle verkeer naar poort 9117 en /jackett loopt nu direct via de Kubernetes pod." diff --git a/k8s/jackett/deployment.yaml b/k8s/jackett/deployment.yaml new file mode 100644 index 0000000..02100e5 --- /dev/null +++ b/k8s/jackett/deployment.yaml @@ -0,0 +1,99 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: jackett + namespace: htpc + labels: + app.kubernetes.io/name: jackett + app.kubernetes.io/part-of: htpc +spec: + replicas: 1 + strategy: + type: Recreate + selector: + matchLabels: + app: jackett + template: + metadata: + labels: + app: jackett + app.kubernetes.io/name: jackett + app.kubernetes.io/part-of: htpc + spec: + nodeSelector: + kubernetes.io/hostname: vmserver + initContainers: + - name: migrate-config + image: lscr.io/linuxserver/jackett:latest + imagePullPolicy: IfNotPresent + command: + - /bin/bash + - -c + - | + if [ ! -f /config/ServerConfig.json ] && [ -f /host-config/ServerConfig.json ]; then + echo "Migrating Jackett config and indexers from host..." + cp -a /host-config/* /config/ + fi + chown -R 33:33 /config + volumeMounts: + - name: config + mountPath: /config + - name: host-config + mountPath: /host-config + readOnly: true + containers: + - name: jackett + image: lscr.io/linuxserver/jackett:latest + imagePullPolicy: IfNotPresent + env: + - name: PUID + value: "33" + - name: PGID + value: "33" + - name: TZ + value: "Europe/Amsterdam" + - name: AUTO_UPDATE + value: "false" + ports: + - name: http + containerPort: 9117 + hostPort: 9117 + protocol: TCP + resources: + requests: + cpu: 100m + memory: 256Mi + limits: + cpu: 1000m + memory: 1Gi + volumeMounts: + - name: config + mountPath: /config + - name: datadisk + mountPath: /datadisk + livenessProbe: + httpGet: + path: /jackett/health + port: 9117 + initialDelaySeconds: 30 + periodSeconds: 20 + timeoutSeconds: 5 + readinessProbe: + httpGet: + path: /jackett/health + port: 9117 + initialDelaySeconds: 15 + periodSeconds: 10 + timeoutSeconds: 5 + volumes: + - name: config + persistentVolumeClaim: + claimName: jackett-config + - name: host-config + hostPath: + path: /home/bart/.config/Jackett + type: DirectoryOrCreate + - name: datadisk + hostPath: + path: /datadisk + type: Directory diff --git a/k8s/jackett/kustomization.yaml b/k8s/jackett/kustomization.yaml new file mode 100644 index 0000000..48bc1a4 --- /dev/null +++ b/k8s/jackett/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - pvc.yaml + - service.yaml + - deployment.yaml diff --git a/k8s/jackett/pvc.yaml b/k8s/jackett/pvc.yaml new file mode 100644 index 0000000..beaa990 --- /dev/null +++ b/k8s/jackett/pvc.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: jackett-config + namespace: htpc + labels: + app.kubernetes.io/name: jackett + app.kubernetes.io/part-of: htpc +spec: + accessModes: + - ReadWriteOnce + storageClassName: local-path + resources: + requests: + storage: 10Gi diff --git a/k8s/jackett/service.yaml b/k8s/jackett/service.yaml new file mode 100644 index 0000000..6ec08c6 --- /dev/null +++ b/k8s/jackett/service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: jackett + namespace: htpc + labels: + app.kubernetes.io/name: jackett + app.kubernetes.io/part-of: htpc +spec: + type: ClusterIP + ports: + - port: 9117 + targetPort: 9117 + protocol: TCP + name: http + selector: + app: jackett diff --git a/k8s/kustomization.yaml b/k8s/kustomization.yaml index f937603..b96fe3a 100644 --- a/k8s/kustomization.yaml +++ b/k8s/kustomization.yaml @@ -10,5 +10,6 @@ resources: - lidarr - transmission - slskd + - jackett diff --git a/migrate_jackett_to_cluster.sh b/migrate_jackett_to_cluster.sh new file mode 100755 index 0000000..40298be --- /dev/null +++ b/migrate_jackett_to_cluster.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +# ============================================================================== +# Jackett Migration Script: Host Service -> Kubernetes Cluster (htpc namespace) +# ============================================================================== +set -euo pipefail + +CLUSTER_HOST="10.2.0.4" +SSH_USER="bart" +HTPC_NS="htpc" +BACKUP_DIR="/storage/backups" +DATE_STR=$(date +%Y-%m-%d) +KUBECONFIG_PATH="${KUBECONFIG:-$HOME/.kube/config_vmserver}" + +COLOR_GREEN="\033[0;32m" +COLOR_YELLOW="\033[1;33m" +COLOR_RED="\033[0;31m" +COLOR_BLUE="\033[0;34m" +COLOR_RESET="\033[0m" + +log_info() { echo -e "${COLOR_GREEN}[INFO]${COLOR_RESET} $1"; } +log_step() { echo -e "\n${COLOR_BLUE}==>${COLOR_RESET} ${COLOR_GREEN}$1${COLOR_RESET}"; } +log_warn() { echo -e "${COLOR_YELLOW}[WARN]${COLOR_RESET} $1"; } +log_err() { echo -e "${COLOR_RED}[ERROR]${COLOR_RESET} $1"; } + +echo "========================================================================" +echo " JACKETT MIGRATIE NAAR KUBERNETES CLUSTER (NAMESPACE: ${HTPC_NS})" +echo "========================================================================" +echo "Bron: jackett.service op ${CLUSTER_HOST}" +echo "Config: /home/bart/.config/Jackett" +echo "Doel: K8s Pod in namespace '${HTPC_NS}' op ${CLUSTER_HOST}" +echo "Poort: 9117 (ClusterIP & HostPort 9117)" +echo "========================================================================" +echo "" + +read -p "Weet je zeker dat je de Jackett migratie naar Kubernetes wilt starten? (j/N): " -r CONFIRM +if [[ ! "$CONFIRM" =~ ^[jJyY]$ ]]; then + log_info "Migratie geannuleerd." + exit 0 +fi + +# ------------------------------------------------------------------------------ +# STAP 1: PRE-FLIGHT CHECKS +# ------------------------------------------------------------------------------ +log_step "1. Pre-flight checks uitvoeren..." + +log_info "Verbinding testen naar host (${CLUSTER_HOST})..." +ssh -o BatchMode=yes -o ConnectTimeout=5 "${SSH_USER}@${CLUSTER_HOST}" "true" || { + log_err "Kan niet verbinden met host (${CLUSTER_HOST}) via SSH." + exit 1 +} + +# ------------------------------------------------------------------------------ +# STAP 2: RESERVEKOPIE MAKEN VAN JACKETT DATA +# ------------------------------------------------------------------------------ +log_step "2. Reservekopie maken van /home/bart/.config/Jackett op ${CLUSTER_HOST}..." +ssh -t "${SSH_USER}@${CLUSTER_HOST}" " + sudo mkdir -p '${BACKUP_DIR}' + if [ -d '/home/bart/.config/Jackett' ]; then + echo 'Inpakken van Jackett config naar ${BACKUP_DIR}/jackett_backup_${DATE_STR}.tar.gz...' + sudo tar -czf '${BACKUP_DIR}/jackett_backup_${DATE_STR}.tar.gz' -C /home/bart/.config Jackett + echo 'Backup gereed:' + ls -lh '${BACKUP_DIR}/jackett_backup_${DATE_STR}.tar.gz' + fi +" + +# ------------------------------------------------------------------------------ +# STAP 3: STANDALONE JACKETT SERVICE STOPPEN OP DE HOST +# ------------------------------------------------------------------------------ +log_step "3. Standalone jackett.service stoppen op ${CLUSTER_HOST}..." +ssh -t "${SSH_USER}@${CLUSTER_HOST}" " + echo '--> Stoppen van jackett.service...' + sudo systemctl stop jackett +" + +# ------------------------------------------------------------------------------ +# STAP 4: KUBERNETES MANIFESTS TOEPASSEN +# ------------------------------------------------------------------------------ +log_step "4. Kubernetes manifests toepassen..." +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +KUBECONFIG="${KUBECONFIG_PATH}" kubectl apply -k "${SCRIPT_DIR}/k8s/" + +log_info "Wachten op succesvolle uitrol van Jackett pod..." +KUBECONFIG="${KUBECONFIG_PATH}" kubectl rollout status deployment/jackett -n "${HTPC_NS}" --timeout=120s + +# ------------------------------------------------------------------------------ +# STAP 5: VERIFICATIE +# ------------------------------------------------------------------------------ +log_step "5. Verificatie van endpoints..." +sleep 5 + +log_info "Health endpoint testen via host (poort 9117)..." +ssh -o BatchMode=yes "${SSH_USER}@${CLUSTER_HOST}" "curl -I -s http://127.0.0.1:9117/jackett/health" | head -n 1 + +log_info "Cluster IP service testen..." +CLUSTER_IP=$(KUBECONFIG="${KUBECONFIG_PATH}" kubectl get svc jackett -n "${HTPC_NS}" -o jsonpath='{.spec.clusterIP}') +ssh -o BatchMode=yes "${SSH_USER}@${CLUSTER_HOST}" "curl -I -s http://${CLUSTER_IP}:9117/jackett/health" | head -n 1 + +echo "" +echo "========================================================================" +log_info "JACKETT MIGRATIE SUCCESVOL AFGEROND!" +echo "Jackett draait nu als pod in Kubernetes namespace '${HTPC_NS}'." +echo "Configuratie en indexers zijn bewaard in PersistentVolume jackett-config." +echo "URL via Apache: https://thuus.bnhmeijer.nl/jackett/" +echo "Direct LAN: http://10.2.0.4:9117/jackett/" +echo "Host service uitschakelen / opruimen kan via: ./cleanup_old_jackett.sh" +echo "========================================================================"