Updated on 2024-04-15 GMT+08:00

Application Backup

Application migration from clusters in an on-premises IDC consists of two steps: application backup and application migration. That is, applications in the clusters in an on-premises IDC are backed up and then migrated to the destination cluster through data restoration.

k8clone is a simple Kubernetes metadata cloning tool. It can save Kubernetes metadata (objects) as a local package and restore the metadata to the destination cluster (Huawei Cloud cluster or on-premises cluster of UCS). In this way, applications can be migrated from clusters in an on-premises data center to the cloud.

Back up data during off-peak hours.

Prerequisites

Ensure that services (data not in the cluster, such as images, storage, and databases) on which cloud native applications depend have been migrated.

How k8clone Backs Up Data

Data backup process:

Figure 1 Data backup process

k8clone Usage for Backup

k8clone can run on Linux (x86 and Arm) and Windows. The usage is similar in both environments. This section uses the Linux (x86) environment as an example.

If Linux (Arm) or Windows is used, replace k8clone-linux-amd64 in the following command with k8clone-linux-arm64 or k8clone-windows-amd64.exe.

Run ./k8clone-linux-amd64 backup -h in the directory where k8clone is located to learn about its usage.

  • -k, --kubeconfig: specifies the location of the kubeconfig file of kubectl. The default value is $HOME/.kube/config. The kubeconfig file is used to configure access to the Kubernetes cluster. The kubeconfig file contains the authentication credentials and endpoints (access addresses) required for accessing and registering the Kubernetes cluster. For details, see the Kubernetes documentation.
  • -s, --api-server: Kubernetes API Server URL. The default value is "".
  • -q, --context: Kubernetes Configuration Context. The default value is "".
  • -n, --namespace: backs up cloud native applications of a specified namespace. Multiple namespaces are separated by commas (,), for example, ns1,ns2,ns3. The default value is "", indicating that the entire cluster is backed up.
  • -e, --exclude-namespaces: excludes the backup of objects of a specified namespace. This parameter cannot be used together with --namespace.
  • -x, --exclude-kind: excludes the backup of a specified resource type.
  • -i, --include-kind: specifies the backup of a resource type.
  • -y, --exclude-object: excludes the backup of a specified resource object.
  • -z, --include-object: specifies the backup of a resource object.
  • -w, --exclude-having-owner-ref: excludes the backup of resource objects with ownerReferences. The default value is false. The equal sign (=) must be contained in the parameter transfer process, for example, -w=true.
  • -d, --local-dir: path for storing backup data. The default value is the k8clone-dump folder in the current directory.
$ ./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         Resource 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

Examples:

  • Backs up objects of the entire cluster. The default path is the k8clone-dump folder in the current directory.

    ./k8clone-linux-amd64 backup

  • Backs up objects of the entire cluster and specifies the path for storing backup data.

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

  • Backs up objects of a specified namespace.

    ./k8clone-linux-amd64 backup -n default

  • Excludes the backup of objects of a specified namespace.

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

  • Excludes the backup of specified resource types.

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

  • Specifies the backup of resource types.

    ./k8clone-linux-amd64 backup -x rolebinding

  • Excludes the backup of specified resource objects.

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

  • Specifies the backup of resource objects.

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

  • Excludes the backup of resource objects with ownerReferences.

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

Procedure

  1. Connect to the source cluster using kubectl. For details, see Connecting to a Cluster Using kubectl.
  2. Go to the directory where k8clone is located and run the backup command to back up data to a local directory and compress the data into a package.

    The examples in k8clone Usage for Backup provide several common backup methods. You can select a method as required or customize one.