Post

SyncThing - Continous file synchronization to remote instances

SyncThing - Continous file synchronization to remote instances

Syncthing is a continuous file synchronization program. It synchronizes files between two or more computers in real time, safely protected from prying eyes. Your data is your data alone and you deserve to choose where it is stored, whether it is shared with some third party, and how it’s transmitted over the internet.

I have syncthing configured to sync my “appdata” of my Docker Swarm to 2 of my friends home servers, this provides a simple but effective offsite backup solution

Since a lot of migration stuff this isn’t currently configured, other backups are in place though, like PBS, DBBackup and Longhorn Backups.

Kubernetes Manifest

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: syncthing
    app.kubernetes.io/instance: syncthing
    app.kubernetes.io/name: syncthing
  name: syncthing
  namespace: syncthing
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: syncthing
  template:
    metadata:
      labels:
        app: syncthing
        app.kubernetes.io/name: syncthing
    spec:
      nodeSelector:
        nas: "true"
      containers:
      - image: linuxserver/syncthing
        name: syncthing
        ports:
          - containerPort: 22000
            hostPort: 22000
            protocol: TCP
          - containerPort: 22000
            hostPort: 22000
            protocol: UDP
          - containerPort: 21027
            hostPort: 21027
            protocol: UDP
          - containerPort: 8384
            hostPort: 8384
            protocol: TCP
        env:
        - name: TZ
          value: Europe/London
        volumeMounts:
        - mountPath: "/backup"
          readOnly: false
          name: smb
        - mountPath: "/config"
          readOnly: false
          name: data
      volumes:
        - name: smb
          persistentVolumeClaim:
            claimName: pvc-syncthing-smb
        - name: data
          persistentVolumeClaim:
            claimName: syncthing
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: syncthing
  name: syncthing
  namespace: syncthing 
spec:
  ports:
  - name: web-tcp
    port: 8384
    protocol: TCP
    targetPort: 8384
  - name: tcp
    port: 22000
    protocol: TCP
    targetPort: 22000
  - name: udp
    port: 22000
    protocol: UDP
    targetPort: 22000
  - name: udp2
    port: 21027
    protocol: UDP
    targetPort: 21027
  type: LoadBalancer
  loadBalancerIP: 10.0.10.203
  selector:
    app: syncthing
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: syncthing
  namespace: syncthing
  annotations: 
    kubernetes.io/ingress.class: traefik-external
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`syncthing.f9.casa`)
      kind: Rule
      services:
        - name: syncthing
          port: 8384
      middlewares:
        - name: default-headers
          namespace: default
        - name: authentik
          namespace: authentik
  tls:
    secretName: f9-casa-tls

Docker Compose

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
version: '3.9'
services:
  syncthing:
    image: syncthing/syncthing
    hostname: syncthing
    networks:
      - traefik-public
    environment:
      - TZ=Europe/London
      - PUID=1000
      - PGID=1000
    volumes:
      - /srv/cephfs/docker/appdata/syncthing:/var/syncthing
      - /srv/cephfs/docker:/userdata
      - /srv/backup/Syncthing:/backup
    ports:
      - 22000:22000/tcp # TCP file transfers
      - 22000:22000/udp # QUIC file transfers
      - 21027:21027/udp # Receive local discovery broadcasts
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.syncthing.rule=Host(`syncthing.f9.casa`)"
        - "traefik.http.services.syncthing.loadbalancer.server.port=8384"
        - "traefik.http.routers.syncthing.entrypoints=websecure"
        - "traefik.http.routers.syncthing.tls=true"
        - "traefik.http.routers.syncthing.tls.certresolver=letsencrypt"

        - "traefik.http.routers.syncthing.middlewares=authentik@docker"
      mode: replicated
networks:
  traefik-public:
    external: true
This post is licensed under CC BY 4.0 by the author.