Technotes

Technotes for future me

Kubernetes copy data between pvc

To copy data between pvc’s, for example during a failed in place restore, follow the procedure below:

Make sure both pvc’s exist, manually or via a Portworx restore.

Create a “copy pod” deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    run: copypod
  name: copypod
  namespace: default # name space of existing "old-data" pvc
spec:
  replicas: 1
  selector:
    matchLabels:
      run: copypod
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: copypod
    spec:
      containers:
        - args:
            - sleep
            - "1000000"
          image: centos
          volumeMounts:
            - mountPath: /new
              name: new-data
            - mountPath: /old
              name: old-data
          imagePullPolicy: Always
          name: copypod
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: stork
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
        - name: new-data
          persistentVolumeClaim:
            claimName: database-data-harbor-database-0 # existing pvc
        - name: old-data
          persistentVolumeClaim:
            claimName: database-data-harbor-database-0-new # newly restored pvc
kubectl apply -f deploy.yaml

Exec in the pod

kubectl exec -it -n platform $(kubectl get pods -n platform | grep copypod | cut -d\  -f1) bash

Once in the pod install rsync, set access rights and start rsync process

yum install -y rsync
chown --reference=/old /new
chmod --reference=/old /new
rsync -rpa /old/ /new
exit

Finally delete the obsolete “copy pod"deployment

kubectl delete -f deploy.yaml
Last updated on 8 Jan 2026
Published on 31 Aug 2021
Edit on GitHub