Do you want to change Storageclass to your PVs?
If the answer is yes, then keep reading, in the past few days one of my clients ask me to migrate the Kubernetes Cluster from GKE to a different Cloud provider as an unmanaged cluster, I believe the most difficult and time consuming task is to migrate the data from the GKE cluster to a unmanaged cluster, so I decided to use Longhorn as part of my solution to the problem but in the GKE cluster we didn’t use Longhorn as a result the Persistent volumes was the gcp native storageclass (kubernetes.io/gce-pd) after googling the problem I have decided to use Rsync to copy the data between pvs. So the approach I have followed is the following I provision the respective pvc/pv with storageclass longhorn. I have build a simple rsync docker image. I have deployed a simple pod to copy the data from the original pvc to the new pvc. cat
If the answer is yes, then keep reading, in the past few days one of my clients ask me to migrate the Kubernetes Cluster from GKE to a different Cloud provider as an unmanaged cluster, I believe the most difficult and time consuming task is to migrate the data from the GKE cluster to a unmanaged cluster, so I decided to use Longhorn as part of my solution to the problem but in the GKE cluster we didn’t use Longhorn as a result the Persistent volumes was the gcp native storageclass (kubernetes.io/gce-pd) after googling the problem I have decided to use Rsync to copy the data between pvs. So the approach I have followed is the following
- I provision the respective pvc/pv with storageclass longhorn.
- I have build a simple rsync docker image.
- I have deployed a simple pod to copy the data from the original pvc to the new pvc.
cat << EOF | k apply -f-
apiVersion: v1
kind: Pod
metadata:
name: migrate-pv-1
namespace: default
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- ""
containers:
- command:
- sh
- -c
- |
set -x
n=0
rc=1
retries=10
attempts=$((retries+1))
period=5
while [[ $n -le $retries ]]
do
rsync -av --info=progress2,misc0,flist0 --no-inc-recursive -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5" -z /source// /dest// && rc=0 && break
n=$((n+1))
echo "rsync attempt $n/$attempts failed, waiting $period seconds before trying again"
sleep $period
done
if [[ $rc -ne 0 ]]; then
echo "rsync job failed after $retries retries"
fi
exit $rc
image: /rsync-image:v1
name: rsync
volumeMounts:
- mountPath: /source
name: vol-0
readOnly: true
- mountPath: /dest
name: vol-1
restartPolicy: Never
volumes:
- name: vol-0
persistentVolumeClaim:
claimName: data-minio-distributed-0
readOnly: true
- name: vol-1
persistentVolumeClaim:
claimName: minio-distributed-0
EOF
Another option is to use the folowing awesome project https://github.com/utkuozdemir/pv-migrate
Thank you.