一个开源的文件同步工具,支持多种平台。
mkdir -pv /opt/syncthing/data
vim /opt/syncthing/compose.yaml
version: '3.9'
services:
syncthing:
image: syncthing/syncthing:1.27.3
container_name: syncthing
restart: always
# 使用 host 模式时
network_mode: host
# 使用 bridge 模式时
ports:
- 30000:8384
- 30001:22000
volumes:
- /etc/localtime:/etc/localtime:ro
- ./data:/data
environment:
- STGUIADDRESS="0.0.0.0:30000"
说明:
8384
为 WebUI 的端口,22000
为同步文件的端口STGUIADDRESS
指定了 GUI 监听地址,默认为 0.0.0.0:8384
,如使用其他端口,则需修改docker-compose -f /opt/syncthing/compose.yaml up -d
mkdir -pv /app/syncthing/data
vim /app/syncthing/syncthing.yaml
# ---
#
# # 创建 Namespace
# apiVersion: v1
# kind: Namespace
# metadata:
# name: hty1024-app
#
---
# 创建 StorageClass
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: storage-local-syncthing
labels:
app.k8s.hty1024.com/env: prod
app.k8s.hty1024.com/type: app
app.k8s.hty1024.com/name: syncthing
app.k8s.hty1024.com/version: 1.27.3
app.k8s.hty1024.com/resources: storageClass
provisioner: kubernetes.io/no-provisioner
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer
---
# 创建 PersistentVolume
apiVersion: v1
kind: PersistentVolume
metadata:
name: hty1024-app-syncthing-pv
labels:
app.k8s.hty1024.com/env: prod
app.k8s.hty1024.com/type: app
app.k8s.hty1024.com/name: syncthing
app.k8s.hty1024.com/version: 1.27.3
app.k8s.hty1024.com/resources: persistentVolume
spec:
capacity:
storage: 100Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: storage-local-syncthing
local:
path: /app/syncthing/data
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: node.k8s.hty1024.com/type
operator: In
values:
- app
---
# 创建 PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: hty1024-app-syncthing-pvc
namespace: hty1024-app
labels:
app.k8s.hty1024.com/env: prod
app.k8s.hty1024.com/type: app
app.k8s.hty1024.com/name: syncthing
app.k8s.hty1024.com/version: 1.27.3
app.k8s.hty1024.com/resources: persistentVolumeClaim
spec:
resources:
requests:
storage: 100Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
storageClassName: storage-local-syncthing
---
# 创建 Service
apiVersion: v1
kind: Service
metadata:
name: hty1024-app-syncthing-service
namespace: hty1024-app
labels:
app.k8s.hty1024.com/env: prod
app.k8s.hty1024.com/type: app
app.k8s.hty1024.com/name: syncthing
app.k8s.hty1024.com/version: 1.27.3
app.k8s.hty1024.com/resources: service
spec:
type: NodePort
ports:
- name: webui
protocol: TCP
port: 30000
targetPort: 30000
nodePort: 30000
- name: tcp
protocol: TCP
port: 22000
targetPort: 22000
nodePort: 30001
selector:
app.k8s.hty1024.com/env: prod
app.k8s.hty1024.com/type: app
app.k8s.hty1024.com/name: syncthing
app.k8s.hty1024.com/version: 1.27.3
app.k8s.hty1024.com/resources: pod
---
# 创建 StatefulSet
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: hty1024-app-syncthing-statefulset
namespace: hty1024-app
labels:
app.k8s.hty1024.com/env: prod
app.k8s.hty1024.com/type: app
app.k8s.hty1024.com/name: syncthing
app.k8s.hty1024.com/version: 1.27.3
app.k8s.hty1024.com/resources: statefulSet
spec:
replicas: 1
minReadySeconds: 30
selector:
matchLabels:
app.k8s.hty1024.com/env: prod
app.k8s.hty1024.com/type: app
app.k8s.hty1024.com/name: syncthing
app.k8s.hty1024.com/version: 1.27.3
app.k8s.hty1024.com/resources: pod
template:
metadata:
labels:
app.k8s.hty1024.com/env: prod
app.k8s.hty1024.com/type: app
app.k8s.hty1024.com/name: syncthing
app.k8s.hty1024.com/version: 1.27.3
app.k8s.hty1024.com/resources: pod
spec:
terminationGracePeriodSeconds: 60
volumes:
- name: localtime
hostPath:
path: /etc/localtime
- name: hty1024-app-syncthing-data
persistentVolumeClaim:
claimName: hty1024-app-syncthing-pvc
containers:
- name: syncthing
image: syncthing/syncthing:1.27.3
ports:
- name: webui
containerPort: 30000
- name: tcp
containerPort: 30001
volumeMounts:
- name: localtime
mountPath: /etc/localtime
readOnly: true
- name: hty1024-app-syncthing-data
mountPath: /data
env:
- name: STGUIADDRESS
value: "0.0.0.0:30000"
nodeSelector:
node.k8s.hty1024.com/type: app
kubectl apply -f /app/syncthing/syncthing.yaml
默认情况下,WebUI 没有用户名和密码,任何人都可以访问,存在安全隐患,因此建议设置
说明:
为方便理解,按以下规则描述设备:
设备A: 当前文件所在设备
设备B: 需获取设备A中文件的设备