【问题标题】:GKE migrate pv to a new cluster whithin the same GCloud projectGKE 将 pv 迁移到同一 GCloud 项目中的新集群
【发布时间】:2020-04-09 11:22:03
【问题描述】:

我想将现有的 PVC/PV 移动到同一个 Google 项目中的新 GKE 集群。有人可以给我一个提示如何做到这一点吗?

提前致谢!

【问题讨论】:

  • 因此您有 2 个 GKE 集群,并且希望将 PV/PVC 从一个集群移动到另一个集群。我对吗? “新”是什么意思?新版本?或只是“另一个集群”。请更详细地描述该部分。
  • 正确....在同一个项目中从一个集群到另一个集群。新意味着只是另一个集群。

标签: kubernetes google-kubernetes-engine gcloud persistent-volumes persistent-volume-claims


【解决方案1】:

如果新旧 GKE 的区域相同,一种可能的方法是在新 GKE 中创建 PVC 和 PV,作为旧 GKE 的副本,并删除 claimRef。这是我用来复制的未优化的 bash sn-ps

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

当您的新旧集群位于不同区域时 - 使用 Valero,如前所述。

【讨论】:

    【解决方案2】:

    Valero 为您提供备份和恢复 Kubernetes 集群资源和持久卷的工具。您可以通过云提供商或本地运行 Velero。

    【讨论】:

      【解决方案3】:

      如果您尝试在新 gke 集群上的计算引擎上使用预先存在的磁盘,请查看doc。它包含一个带有 yaml 文件的示例,您可能会发现它对实现迁移很有帮助。

      【讨论】:

        猜你喜欢
        • 2021-10-04
        • 2021-06-12
        • 2020-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-08
        • 1970-01-01
        相关资源
        最近更新 更多