0

I would like to move existing PVCs/PVs to a new GKE cluster in the same Google project. Can someone give me a hint how to do this?

Thanks in advance!

Timo Antweiler
  • 171
  • 1
  • 2
  • 11
  • so you have 2 GKE clusters and would like moving PVs/PVCs from one cluster to another. Am I right? What means "new"? New version? or just "another cluster" . Please describe that part in more details. – Nick Apr 09 '20 at 21:47
  • Correct....from one cluster to another in the same project. New means just another cluster. – Timo Antweiler Apr 14 '20 at 09:28

3 Answers3

3

In case of same zone(s) of old and new GKEs one possible way is to create PVCs & PVs in a new GKE as a copy from old GKE with claimRef removal. Here are my unoptimized bash snippets I use to copy

SRC=src_k8s_context
DST=dst_k8s_context

# copy NS
kubectl --context $SRC get ns -o name|cut -d '/' -f 2|xargs -n1 kubectl --context $DST create ns

# copy PV
for PV in $(kubectl --context $SRC get pv -o name|cut -d '/' -f 2); do kubectl --context $SRC get pv $PV -o yaml --export|kubectl --context $DST create -f -;done

# copy PVC
tmp=$IFS;IFS=$'\n';for a in $(kubectl --context $SRC get pvc -A|tail -n +2|awk '{print "NS="$1" PVC="$2}');do eval $a; kubectl --context $SRC --namespace $NS get pvc $PVC -o yaml --export | kubectl --context $DST --namespace $NS create -f -;done; IFS=$tmp

# stop all required pods in old GKE, my case is StatefulSet's in all namespaces
for NS in $(kubectl --context $SRC get ns -o name|cut -d '/' -f 2); do kubectl --context $SRC -n $NS scale statefulset --all --replicas=0;done

# cleanup PV's in a new GKE from links to old GKE PVC
for PV in $(kubectl --context $DST get pv -o name|cut -d '/' -f 2); do kubectl --context $DST patch pv $PV  --type json   -p='[{"op": "remove", "path": "/spec/claimRef"}]';done

When Your old and new clusters are located in different regions - use Velero, as already mentioned.

Alex Vorona
  • 1,875
  • 1
  • 9
  • 7
1

Valero gives you tools to back up and restore your Kubernetes cluster resources and persistent volumes. You can run Velero with a cloud provider or on-premises.

Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
0

If you are trying to use preexisting disks on compute engine on new gke cluster, have a look at this doc. It contains an example with yaml file that you might find helpful in order to achieve your migration.

dany L
  • 2,456
  • 6
  • 12