Files
go-otel/k8s/migrate/clickhouse-nfs-to-local.yaml
2026-09-19 14:13:43 +02:00

58 lines
1.9 KiB
YAML

# One-off: copy ClickHouse data from the old NFS PVC to serber:/srv/monitoring-db.
# NOT applied by `kubectl apply -f k8s/` (subdirectory). Run it while the
# StatefulSet is scaled to 0 so the copy is consistent:
#
# kubectl scale sts clickhouse -n monitoring --replicas=0
# kubectl apply -f k8s/migrate/clickhouse-nfs-to-local.yaml
# kubectl wait --for=condition=complete job/clickhouse-nfs-to-local -n monitoring --timeout=30m
# kubectl delete sts clickhouse -n monitoring # PVC is retained (rollback copy)
# kubectl apply -f k8s/clickhouse.yaml # new hostPath StatefulSet
# kubectl delete job clickhouse-nfs-to-local -n monitoring
#
# The old PVC (data-clickhouse-0) is left untouched until you delete it.
apiVersion: batch/v1
kind: Job
metadata:
name: clickhouse-nfs-to-local
namespace: monitoring
spec:
backoffLimit: 0
template:
spec:
restartPolicy: Never
nodeSelector:
kubernetes.io/hostname: serber
containers:
- name: copy
image: busybox:1.36
securityContext:
runAsUser: 0
command:
- sh
- -c
- |
set -eu
if [ -n "$(ls -A /new 2>/dev/null)" ]; then
echo "refusing to copy: /new (serber:/srv/monitoring-db) is not empty"; exit 1
fi
du -sh /old
cp -a /old/. /new/
chown -R 101:101 /new
echo "old: $(find /old -type f | wc -l) files, new: $(find /new -type f | wc -l) files"
[ "$(find /old -type f | wc -l)" = "$(find /new -type f | wc -l)" ]
volumeMounts:
- name: old
mountPath: /old
readOnly: true
- name: new
mountPath: /new
volumes:
- name: old
persistentVolumeClaim:
claimName: data-clickhouse-0
readOnly: true
- name: new
hostPath:
path: /srv/monitoring-db
type: DirectoryOrCreate