All Products
Search
Document Center

Container Service for Kubernetes:Migrate applications across clusters in different regions

Last Updated:Sep 05, 2024

The backup center feature can be used to back up and restore applications across clusters in different regions. This enables cross-region backup and disaster recovery.

Prerequisites

  • A cluster where the volume is restored is created. To ensure that you can use snapshots of Elastic Compute Service (ECS) instances to restore disk data, we recommend that you update the Kubernetes version of the cluster to 1.18 or later. For more information, see Create an ACK managed cluster, Create an ACK dedicated cluster, or Create a cluster registration proxy and register a Kubernetes cluster that is deployed in a data center.

    Important
    • The restore cluster must use the Container Storage Interface (CSI) plug-in. Application restoration is not supported in clusters that use FlexVolume or use csi-compatible-controller and FlexVolume.

    • The backup center is used to back up and restore applications. Before you run a restore task, you must install and configure system components in the restore cluster. Example:

      • aliyun-acr-credential-helper: You need to grant permissions to the restore cluster and configure acr-configuration.

      • alb-ingress-controller: You need to configure an ALBConfig.

  • The backup component is installed and permissions are granted in the cluster where the volume is backed up and the cluster where the volume is restored. For more information, see Install migrate-controller and grant permissions.

  • ECS Snapshot is activated.

    No fee is charged for activating the ECS Snapshot service. After you create snapshots, you are charged for the snapshots based on their size and retention period. For more information, see Snapshots.

Usage notes

  • Cross-region migration supports application backup. You can also use cross-region migration to back up volumes that use Alibaba Cloud disks.

    If you use an ACK dedicated cluster or registered cluster that connects to a self-managed Kubernetes cluster consisting of Elastic Compute Service (ECS) nodes, you need to check whether the ECS Snapshot permissions are granted to the cluster before you can migrate applications across clusters in different regions. For more information, see Install migrate-controller and grant permissions.

  • When the backup center backs up applications, the resources that are being deleted are not backed up.

Preparations

The example in this topic shows how to back up and restore applications across clusters in different regions. In this example, an ACK Pro cluster named Cluster_BJ is created in the China (Beijing) region and used as the source cluster to back up applications. An ACK Pro cluster named Cluster_SZ is created in the China (Shenzhen) region and used as the destination cluster to restore applications. A backup vault is associated with an Object Storage Service (OSS) bucket in the China (Beijing) region.

  1. Create an OSS bucket named cnfs-oss-*** in the China (Beijing) region.

    Skip this step if an OSS bucket that meets the requirement is already created in the region.

  2. Run the following command to create a stateful NGINX application in the default namespace of the Cluster_BJ cluster.

    YAML file of the stateful Nginx application

    cat << EOF | kubectl apply -f -
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: web
    spec:
      selector:
        matchLabels:
          app: nginx
      serviceName: "nginx"
      replicas: 1
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
            - name: nginx
              image: nginx:1.14.2
              ports:
                - containerPort: 80
                  name: web
              volumeMounts:
                - name: www
                  mountPath: /usr/share/nginx/html
      volumeClaimTemplates:
        - metadata:
            name: www
            labels:
              app: nginx
          spec:
            accessModes: [ "ReadWriteOnce" ]
            storageClassName: "alicloud-disk-topology-alltype"
            resources:
              requests:
                storage: 20Gi
    EOF

Step 1: Create a backup vault

Note
  • The network access mode between the backup vault in each cluster and the associated OSS bucket is automatically configured. The backup file upload and download speeds vary based on the network access mode.

    • If the cluster and OSS bucket are created in the same region, a private connection is used.

    • If the cluster and OSS bucket are created in different regions, an Internet connection is used. You must ensure that the cluster has Internet access to reach the public endpoint of OSS. For more information, see Enable an existing ACK cluster to access the Internet.

  • You can only delete existing backup vaults. You cannot update existing backup vaults. If you create a backup vault that has the same name as a deleted backup vault, the backup vault that you create cannot be used by clusters that have used the application backup feature.

When you back up applications in an ACK cluster, the backup files are stored in an OSS bucket. If no backup vault is available when you create a backup plan, you must perform the operations in Step 1. For more information about how to create a backup vault, see Create a backup vault.

Step 2: Create a backup plan in the Cluster_BJ cluster

For more information about how to create a backup plan, see Create a backup plan or back up instantly.

Important

You can migrate only applications that do not use volumes or applications that use Alibaba Cloud disk volumes across clusters in different regions. To avoid cross-region restoration failures, do not enable volume backup when you migrate stateful applications that use other types of volumes.

Step 3: Restore applications to the Cluster_SZ cluster

For more information about how to restore applications, see Step 3: Restore applications and volumes.

Step 4: Check whether the NGINX application is migrated

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. In the left-side navigation pane of the Cluster_SZ cluster management page, choose Workloads > Deployments.

  3. Click Details in the Actions column of the NGINX application. Then, click the Pods tab.

    If the status of the pods is Running, the NGINX application is migrated.

References