ADD: implement migration and backup configurations for Nextcloud with Longhorn support

This commit is contained in:
2026-04-15 19:51:29 +02:00
parent 2ea9f3973f
commit be9329d313
15 changed files with 326 additions and 27 deletions
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Pod
metadata:
name: mariadb-backup
namespace: nextcloud
spec:
nodeName: knode0 # <-- FIXED ON node0
containers:
- name: backup
image: busybox
command: ["sleep", "3600"]
volumeMounts:
- name: old
mountPath: /old
volumes:
- name: old
persistentVolumeClaim:
claimName: nextcloud-mariadb-pvc
@@ -0,0 +1,34 @@
apiVersion: v1
kind: Pod
metadata:
name: config-migration
namespace: nextcloud
spec:
volumes:
- name: old-config
persistentVolumeClaim:
claimName: nextcloud-config-pvc
- name: new-config
persistentVolumeClaim:
claimName: nextcloud-config-pvc-longhorn
containers:
- name: migrator
image: alpine:3.18
volumeMounts:
- name: old-config
mountPath: /old
- name: new-config
mountPath: /new
command: ['sh']
args:
- -c
- |
echo "Copying config data..."
if [ "$(ls -A /old)" ]; then
cp -rv /old/* /new/ 2>/dev/null || true
echo "Config migration completed"
else
echo "Old config is empty"
fi
sleep infinity
restartPolicy: Never
@@ -0,0 +1,34 @@
apiVersion: v1
kind: Pod
metadata:
name: apps-migration
namespace: nextcloud
spec:
volumes:
- name: old-apps
persistentVolumeClaim:
claimName: nextcloud-apps-pvc
- name: new-apps
persistentVolumeClaim:
claimName: nextcloud-apps-pvc-longhorn
containers:
- name: migrator
image: alpine:3.18
volumeMounts:
- name: old-apps
mountPath: /old
- name: new-apps
mountPath: /new
command: ['sh']
args:
- -c
- |
echo "Copying apps data..."
if [ "$(ls -A /old)" ]; then
cp -rv /old/* /new/ 2>/dev/null || true
echo "Apps migration completed"
else
echo "Old apps is empty"
fi
sleep infinity
restartPolicy: Never
@@ -0,0 +1,12 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nextcloud-mariadb-pvc-longhorn
namespace: nextcloud
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn
resources:
requests:
storage: 10Gi
@@ -0,0 +1,24 @@
apiVersion: v1
kind: Pod
metadata:
name: mariadb-restore
namespace: nextcloud
spec:
nodeName: knode0
containers:
- name: restore
image: busybox
command: ["sleep", "3600"]
volumeMounts:
- name: new
mountPath: /new
- name: oldbackup
mountPath: /backup
volumes:
- name: new
persistentVolumeClaim:
claimName: nextcloud-mariadb-pvc-longhorn
- name: oldbackup
hostPath:
path: /var/lib/nextcloud/mariadb-backup
type: DirectoryOrCreate
@@ -28,6 +28,11 @@ spec:
value: nextcloud
ports:
- containerPort: 3306
readinessProbe:
tcpSocket:
port: 3306
initialDelaySeconds: 5
periodSeconds: 10
resources:
requests:
memory: "256Mi"
@@ -41,4 +46,4 @@ spec:
volumes:
- name: mariadb-data
persistentVolumeClaim:
claimName: nextcloud-mariadb-pvc
claimName: nextcloud-mariadb-pvc-longhorn
@@ -9,24 +9,4 @@ spec:
resources:
requests:
storage: 10Gi
storageClassName: local-path # <-- explicit default StorageClass
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: nextcloud-mariadb-pv
labels:
app: mariadb
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-path
claimRef:
namespace: nextcloud
name: nextcloud-mariadb-pvc
hostPath:
path: /var/lib/nextcloud/mariadb-data
type: DirectoryOrCreate
storageClassName: longhorn
@@ -0,0 +1,12 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nextcloud-apps-pvc-longhorn
namespace: nextcloud
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn
resources:
requests:
storage: 1Gi
@@ -0,0 +1,12 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nextcloud-config-pvc-longhorn
namespace: nextcloud
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn
resources:
requests:
storage: 5Gi
@@ -16,12 +16,19 @@ spec:
# fsGroup sorgt dafür, dass gemountete Volumes die Gruppe www-data (33) bekommen
securityContext:
fsGroup: 33
# Auf knode0 zwingen (hat Kernel 6.1 mit NFS - Kompatibilität)
nodeSelector:
kubernetes.io/hostname: knode0
# hostAliases mappt die öffentliche Domain intern auf die Service-ClusterIP,
# damit der Pod henryathome.home64.de direkt intern erreicht (vermeidet externe Loopback/Firewall/403)
hostAliases:
- ip: "10.43.107.87"
hostnames:
- "henryathome.home64.de"
initContainers:
- name: wait-for-mariadb
image: busybox:1.34
command: ['sh', '-c', 'until nc -z mariadb.nextcloud.svc.cluster.local 3306; do echo waiting for mariadb; sleep 2; done;']
containers:
- name: nextcloud
image: nextcloud:33-apache
@@ -73,7 +80,7 @@ spec:
claimName: nextcloud-data-pvc
- name: config
persistentVolumeClaim:
claimName: nextcloud-config-pvc
claimName: nextcloud-config-pvc-longhorn
- name: apps
persistentVolumeClaim:
claimName: nextcloud-apps-pvc
claimName: nextcloud-apps-pvc-longhorn
@@ -10,10 +10,13 @@ spec:
persistentVolumeReclaimPolicy: Retain
storageClassName: nfs
mountOptions:
- vers=4
- vers=3
- rsize=65536
- wsize=65536
- noatime
- soft
- timeo=20
- retrans=2
nfs:
server: 192.168.178.186 # <-- ERSETZEN: IP oder Hostname deiner NAS
path: /volume1/Nextcloud/data # <-- ERSETZEN: Pfad zum Share auf der NAS (z.B. /volume1/nextcloud)