文档首页> 云容器引擎 CCE> 用户指南> Autopilot集群用户指南> 集群> 将Standard/Turbo集群迁移至Autopilot集群
更新时间:2024-07-02 GMT+08:00

将Standard/Turbo集群迁移至Autopilot集群

将Standard/Turbo集群迁移至Autopilot集群包含两个步骤:应用备份和应用迁移,即备份源AZ集群中应用,然后通过数据恢复的方式迁移至目标AZ集群。

k8clone是一个简便的Kubernetes元数据克隆工具,它可以将Kubernetes元数据(对象)保存为本地压缩包,然后将这些元数据恢复到目标集群中。

k8clone工具下载地址请参见容器迁移准备工作

k8clone数据备份/恢复原理

数据备份的流程参考如下:

图1 数据备份流程

数据恢复的流程参考如下:

图2 数据恢复流程

在执行恢复操作前,需要准备一个数据恢复配置文件“restore.json”,目的是在应用恢复时自动更换PVC、StatefulSet的存储类名称,以及工作负载所使用镜像的Repository地址。

文件内容如下:

{
    "StorageClass": 
          "OldStorageClassName": "NewStorageClassName"  //支持修改PVC、StatefulSet的StorageClassName字段
    "ImageRepo": 
          "OldImageRepo1": "NewImageRepo1",   //eg:"dockerhub.com": "cn-north-4.swr.huaweicloud.com"
          "OldImageRepo2": "NewImageRepo2",   //eg:"dockerhub.com/org1": "cn-north-4.swr.huaweicloud.com/org2"
          "NoRepo": "NewImageRepo3"   //eg:"golang": "swr.cn-north-4.myhuaweicloud.com/paas/golang"
}
  • StorageClass:支持PVC、有状态应用VolumeClaimTemplates中存储类名称按照配置进行自动更换。
  • ImageRepo:支持工作负载所使用镜像的Repository地址的更换,工作负载包括Deployment(含initContainer)、StatefulSet、Orphaned Pod、Job、CronJob、Replica Set、Replication Controller、DaemonSet。

应用备份操作步骤

  1. 通过kubectl连接源集群。具体方法可参考使用kubectl连接集群
  2. 进入k8clone工具所在目录,执行备份命令,即可备份数据到本地目录,并打包成压缩包。

    k8clone备份使用方法的示例中提供了几种常见的备份方式,您可以按需选择,也可以自定义备份方式。

应用恢复操作步骤

  1. 通过kubectl连接目标集群。具体方法可参考使用kubectl连接集群
  2. 准备数据恢复配置文件:restore.json。

    新建一个restore.json文件,按照格式修改,并将文件放置在k8clone工具所在目录下。

    示例:

    {
      "StorageClass": {
        "csi-disk": "csi-disk-new"
      },
      "ImageRepo": {
        "quay.io/coreos": "swr.cn-north-4.myhuaweicloud.com/paas"
      }
    }

  3. 进入k8clone工具所在目录,执行恢复命令,将备份数据恢复到目标集群。

    示例:

    ./k8clone-linux-amd64 restore -d ./k8clone-dump.zip -f ./restore.json

k8clone备份使用方法

k8clone工具支持在Linux(x86、arm)和Windows环境中运行,使用方法相似。本文将以Linux(x86)环境为例进行介绍。

若使用Linux(arm)或Windows环境,请将下述命令中的k8clone-linux-amd64分别替换为k8clone-linux-arm64k8clone-windows-amd64.exe

在k8clone工具所在目录下执行./k8clone-linux-amd64 backup -h,可以查看k8clone工具备份的使用方法。

  • -k, --kubeconfig:指定kubectl的KubeConfig位置,默认是$HOME/.kube/config。kubeConfig文件:用于配置对Kubernetes集群的访问,KubeConfig文件中包含访问注册Kubernetes集群所需要的认证凭据以及Endpoint(访问地址),详细介绍可参见Kubernetes文档
  • -s, --api-server:Kubernetes API Server URL,默认是""。
  • -q, --context:Kubernetes Configuration Context,默认是""。
  • -n, --namespace:备份指定命名空间的云原生应用,多个命名空间用逗号分隔(如:ns1,ns2,ns3),默认是"",表示备份整个集群。
  • -e, --exclude-namespaces:排除指定命名空间对象的备份,不能和--namespace一起使用。
  • -x, --exclude-kind:排除指定资源类型的备份。
  • -i, --include-kind : 指定资源类型的备份。
  • -y, --exclude-object:排除指定资源对象的备份。
  • -z, --include-object:指定资源对象的备份。
  • -w, --exclude-having-owner-ref:排除拥有ownerReferences资源对象的备份,默认是false。传参过程中需要带上等号,如:-w=true 。
  • -d, --local-dir:备份数据放置的路径,默认是当前目录下k8clone-dump文件夹。
$ ./k8clone-linux-amd64 backup -h
Backup Workload Data as yaml files

Usage:
    k8clone backup [flags]

Flags:
   -s, --api-server string            Kubernetes api-server url
   -q, --context string               Kubernetes configuration context
   -w, --exclude-having-owner-ref     Exclude all objects having an Owner Reference. The following form is not permitted for boolean flags such as '-w false',please use '-w=false'
   -x, --exclude-kind strings         Ressource kind to exclude. Eg. 'deployment'
   -i, --include-kind strings         Ressource kind to include. Eg. 'deployment'
   -e, --exclude-namespaces strings   Namespaces to exclude. Eg. 'temp.*' as regexes. This collects all namespaces and then filters them. Don't use it with the namespace flag.
   -y, --exclude-object strings       Object to exclude. The form is '<kind>:<namespace>/<name>',namespace can be empty when object is not namespaced. Eg. 'configmap:kube-system/kube-dns'
   -z, --include-object strings       Object to include. The form is '<kind>:<namespace>/<name>',namespace can be empty when object is not namespaced. Eg. 'configmap:kube-system/kube-dns' 
   -h, --help                         help for backup
   -k, --kubeconfig string            The kubeconfig of k8s cluster's. Default is the $HOME/.kube/config. 
   -d, --local-dir string             Where to dump yaml files (default "./k8clone-dump")
   -n, --namespace string             Only dump objects from this namespace

示例如下:

  • 整个集群对象的备份,默认路径为当前目录下“k8clone-dump”文件夹

    ./k8clone-linux-amd64 backup

  • 整个集群对象的备份,并指定备份数据路径

    ./k8clone-linux-amd64 backup -d ./xxxx

  • 指定命名空间对象的备份

    ./k8clone-linux-amd64 backup -n default

  • 排除命名空间对象的备份

    ./k8clone-linux-amd64 backup -e kube-system,kube-public,kube-node-lease

  • 排除指定资源类型的备份

    ./k8clone-linux-amd64 backup -x endpoints,endpointslice

  • 指定资源类型的备份

    ./k8clone-linux-amd64 backup -x rolebinding

  • 排除指定资源对象的备份

    ./k8clone-linux-amd64 backup -y configmap:kube-system/kube-dns

  • 指定资源对象的备份

    ./k8clone-linux-amd64 backup -z configmap:kube-system/kube-dns

  • 排除拥有ownerReferences资源对象的备份

    ./k8clone-linux-amd64 backup -w=true

k8clone恢复使用方法

k8clone工具支持在Linux(x86、arm)和Windows环境中运行,使用方法相似。本文将以Linux(x86)环境为例进行介绍。

若使用Linux(arm)或Windows环境,请将下述命令中的k8clone-linux-amd64分别替换为k8clone-linux-arm64k8clone-windows-amd64.exe

在k8clone工具所在目录下执行./k8clone-linux-amd64 restore -h,可以查看k8clone工具恢复的使用方法。

  • -k, --kubeconfig:指定kubectl的KubeConfig位置,默认是$HOME/.kube/config。kubeConfig文件:用于配置对Kubernetes集群的访问,KubeConfig文件中包含访问注册Kubernetes集群所需要的认证凭据以及Endpoint(访问地址),详细介绍可参见Kubernetes文档
  • -s, --api-server:Kubernetes API Server URL,默认是""。
  • -q, --context:Kubernetes Configuration Context,默认是""。
  • -f, --restore-conf:指定restore.json的路径,默认是k8clone工具所在目录下。
  • -d, --local-dir:备份数据放置的路径,默认是k8clone工具所在目录下。
$ ./k8clone-linux-amd64 restore -h
ProcessRestore from backup

Usage:
     k8clone restore [flags]

Flags:
   -s, --api-server string     Kubernetes api-server url
   -q, --context string        Kubernetes configuration context
   -h, --help                  help for restore
   -k, --kubeconfig string     The kubeconfig of k8s cluster's. Default is the $HOME/.kube/config. 
   -d, --local-dir string      Where to restore (default "./k8clone-dump.zip")
   -f, --restore-conf string   restore conf file (default "./restore.json")

示例:

./k8clone-linux-amd64 restore -d ./k8clone-dump.zip -f ./restore.json