Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

将 qbittorrent 从 docker 迁移到 k8s #324

Open
Bpazy opened this issue Apr 5, 2024 · 0 comments
Open

将 qbittorrent 从 docker 迁移到 k8s #324

Bpazy opened this issue Apr 5, 2024 · 0 comments

Comments

@Bpazy
Copy link
Owner

Bpazy commented Apr 5, 2024

1. k8s 集群安装 smb

这里需要用到 csi-driver-smb,如果你的网络环境足够好,直接按照官方文档所述即可安装:

helm repo add csi-driver-smb https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/master/charts
helm install csi-driver-smb csi-driver-smb/csi-driver-smb --namespace kube-system --version v1.14.0

如果你的网络和我一样不够好,那就需要手动安装,这里参考了官方的安装脚本,发现其中主要是 kubectl apply 了几个脚本:

kubectl apply -f csi-smb-controller.yaml
kubectl apply -f csi-smb-driver.yaml
kubectl apply -f csi-smb-node-windows.yaml
kubectl apply -f csi-smb-node.yaml
kubectl apply -f rbac-csi-smb.yaml

这几个脚本中有几个镜像不太好下载,需要替换一下下载源,把这几个文件里的 registry.k8s.io 替换为 k8s.ketches.cn 即可。

k8s.ketches.cn 域名来源于这个项目 ketches/registry-proxy,该项目能自动替换 apply 的脚本里的域名,但是由于我不太喜欢这里的自动,所以就手动替换了。

2. 部署 qbittorrent

准备工作做完,现在可以开始部署 qbittorrent 了,先创建 secret 保存 smb 相关用户名密码:

kubectl create secret generic qbittorrent-smb --from-literal username=这里填写用户名 --from-literal password=这里填写密码

然后准备好 qbittorrent 的 yaml:

apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/provisioned-by: smb.csi.k8s.io
  name: qbittorrent-config-pv-smb
spec:
  capacity:
    storage: 1Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: smb
  mountOptions:
  - dir_mode=0777
  - file_mode=0777
  csi:
    driver: smb.csi.k8s.io
    volumeHandle: 192.168.31.20/qbittorrent/config##
    volumeAttributes:
      source: //192.168.31.20/qbittorrent/config
    nodeStageSecretRef:
      name: qbittorrent-smb
      namespace: default

---
apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/provisioned-by: smb.csi.k8s.io
  name: qbittorrent-downloads-pv-smb
spec:
  capacity:
    storage: 30Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: smb
  mountOptions:
  - dir_mode=0777
  - file_mode=0777
  csi:
    driver: smb.csi.k8s.io
    volumeHandle: 192.168.31.20/Installer/qbittorrent_downloads##
    volumeAttributes:
      source: //192.168.31.20/Installer/qbittorrent_downloads
    nodeStageSecretRef:
      name: qbittorrent-smb
      namespace: default


---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: qbittorrent-config-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 100Mi
  volumeName: qbittorrent-config-pv-smb
  storageClassName: smb

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: qbittorrent-downloads-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 30Gi
  volumeName: qbittorrent-downloads-pv-smb
  storageClassName: smb

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: qbittorrent
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      name: qbittorrent
  template:
    metadata:
      labels:
        name: qbittorrent
    spec:
      nodeSelector:
        type: local
      containers:
      - name: qbittorrent
        image: ghcr.dockerproxy.com/linuxserver/qbittorrent:4.6.4
        ports:
        - containerPort: 8080
        - containerPort: 6881
          protocol: UDP
        volumeMounts:
        - name: config-smb
          mountPath: /config
        - name: downloads-smb
          mountPath: /downloads
        resources:
          limits:
            memory: 2Gi
            cpu: "2"
        env:
        - name: PUID
          value: "0"
        - name: PGID
          value: "0"
        - name: TZ
          value: "Asia/Shanghai"
        - name: WEBUI_PORT
          value: "8080"
        - name: TORRENTING_PORT
          value: "6881"
      volumes:
      - name: config-smb
        persistentVolumeClaim:
          claimName: qbittorrent-config-pvc
      - name: downloads-smb
        persistentVolumeClaim:
          claimName: qbittorrent-downloads-pvc

---
apiVersion: v1
kind: Service
metadata:
  name: qbittorrent
spec:
  type: ClusterIP
  clusterIP: 10.43.235.119
  selector:
    name: qbittorrent
  ports:
  - name: web
    port: 8080
    targetPort: 8080
  - name: udp
    port: 6881
    targetPort: 6881
    protocol: UDP

从 yaml 也能看出我这里用的是固定 IP 的 Service,外部我直接用 nginx 转发到这个 IP 上的。如果你用的是 Ingress 或者 Load Balancer,自行替换相关配置即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant