<p>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? </p>

<p>Thanks in advance! </p>

Timo Antweiler
<p>In case of same zone(s) of old and new GKEs one possible way is to create PVCs &amp; PVs in a new GKE as a copy from old GKE with <code>claimRef</code> removal. Here are my unoptimized bash snippets I use to copy</p>
<pre class="lang-sh prettyprint-override"><code>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 &quot;NS=&quot;$1&quot; PVC=&quot;$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='[{&quot;op&quot;: &quot;remove&quot;, &quot;path&quot;: &quot;/spec/claimRef&quot;}]';done
</code></pre>
<p>When Your old and new clusters are located in different regions - use <a href="https://github.com/vmware-tanzu/velero" rel="nofollow noreferrer">Velero</a>, as already mentioned.</p>
