All Products
Search
Document Center

Container Service for Kubernetes:Cross-VPC application migration by reusing cloud resources

Last Updated:Oct 10, 2026

After an ACK cluster is created, you cannot change its network plug-in or associated Virtual Private Cloud (VPC). If you need to change the cluster's network plug-in (for example, from Flannel to Terway) or VPC, you can create a new cluster with the required configuration in the same region and migrate your applications. Because the region remains the same when you switch the VPC or network plug-in, you can reuse most of your cloud resources, such as storage (disks, NAS, and OSS) and SLB instances. You can use the backup center to migrate applications between clusters in different VPCs.

Prerequisites

Category

Prerequisites

Related actions

Clusters and components

We do not recommend migrating applications from a higher-version cluster to a lower-version cluster.

  • Backup cluster: Kubernetes 1.16 or later.

  • Restore cluster: Kubernetes 1.20 or later (to use the Resource Modifier feature).

    Note
    • To reuse existing NAS volumes and avoid creating extra ones, do not select Create default NAS file system and dynamic StorageClass for CNFS in the Component Configurations step under Volume Plug-in when you create the restore cluster. If you already selected this option, delete the existing alibabacloud-cnfs-nas StorageClass before you proceed.

    • Install and configure the required system components in the restore cluster in advance. For example:

      • ACR password-free component: You need to re-authorize the restore cluster and configure acr-configuration.

      • ALB Ingress component: You need to configure AlbConfig and other resources in advance.

Components required for the backup and restore clusters:

  • CSI plug-in: 1.1.0 or later.

  • migrate-controller component: 1.8.1 or later.

Region

The backup and restore clusters are in the same region.

None

Cloud service required for backup

ECS snapshot

Enable the snapshot service

Usage notes

Backup notes

  • The backup center does not back up resources that are being deleted.

  • If the backup cluster is connected to another cluster through a single VPC for pod-to-pod communication, applications migrated to the cluster in the new VPC cannot access the pods and ECS instances of that cluster. For more information, see Plan the network of an ACK managed cluster.

Restore notes

  • When an application is restored, resources are preferentially restored using the recommended apiVersion for the Kubernetes version of the restore cluster. If a resource does not have an apiVersion that is supported by both cluster versions, you must manually deploy that resource. For example:

    • A Deployment in a Kubernetes 1.16 cluster supports the extensions/v1beta1, apps/v1beta1, apps/v1beta2, and apps/v1 API versions. When restored to a Kubernetes 1.28 cluster, it is restored by using apps/v1.

    • An Ingress in a Kubernetes 1.16 cluster supports the extensions/v1beta1 and networking.k8s.io/v1beta1 API versions. You cannot directly restore it to a cluster that runs Kubernetes 1.22 or later.

    For more information about API changes across Kubernetes versions, see ACK release notes and Deprecated API Migration Guide.

    Important

    In a Kubernetes 1.16 cluster, API groups such as apps and rbac.authorization.k8s.io already support v1. When you migrate applications to a Kubernetes 1.28 cluster, you must manually restore resources such as Ingress and CronJob.

  • When you reuse NAS volumes or OSS buckets, the backup and restore clusters can share read and write access. However, when you reuse an existing disk, the system forcibly detaches it from the original node in the backup cluster before attaching it to a node in the new cluster. Therefore, for disk volumes, back up the volume data and create new disks automatically during restoration.

    Note
    • If you cannot stop your business workloads and cannot tolerate data inconsistency during migration, avoid forceful disk detachment.

    • ESSD volumes support the ECS snapshot instant access feature by default. Backing up these volumes protects your data and can significantly reduce migration time.

Billing

The backup center feature is free of charge. Costs arise from the underlying storage and backup services it relies on.

  • OSS: OSS buckets are used to store backed-up cluster resources, such as YAML files. For information about OSS billing, see Billing overview.

  • Disk snapshot: This feature is used to back up data from Alibaba Cloud disk volumes. For information about snapshot billing, see Snapshots.

    Note
    • Starting from 11:00 on October 12, 2023, Alibaba Cloud ECS no longer charges storage fees or feature fees for the instant access feature of snapshots. For more information, see Instant access to snapshots.

    • When you use ESSD or ESSD AutoPL disks of PL0, PL1, PL2, or PL3, the instant access feature is enabled by default for snapshots created during backups.

Example application

image

The Nginx application is also configured with a LoadBalancer-type Service named nginx-svc. The cloud controller manager (CCM) automatically creates the SLB instance. To determine how the SLB instance is created and for more details, see Considerations for configuring a LoadBalancer Service.

Note

When you create an application, ensure that the RAM user has permissions for the bucket and replace the corresponding url with the bucket's actual endpoint. For more information about how to use OSS static volumes, see Authorize and mount an OSS static volume.

Show the YAML file for the example application

# Dynamically provisioned disk volume
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-disk
spec:
  accessModes:
  - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 20Gi
  storageClassName: alicloud-disk-topology-alltype
---
# Statically provisioned OSS volume
apiVersion: v1
kind: Secret
metadata:
  name: oss-secret
  namespace: default
stringData:
  akSecret: <yourAccessKey Secret>
  akId: <yourAccessKey ID>
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-oss
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  csi:
    driver: ossplugin.csi.alibabacloud.com
    volumeHandle: pv-oss
    nodePublishSecretRef:
      name: oss-secret
      namespace: default
    volumeAttributes:
      bucket: "a-new-bucket"
      url: "http://oss-cn-beijing.aliyuncs.com"
      otherOpts: "-o allow_other -oumask=000"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-oss
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
  volumeName: pv-oss
---
# Dynamically provisioned NAS volume
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-nas
spec:
  accessModes:
  - ReadWriteMany
  volumeMode: Filesystem
  resources:
    requests:
      storage: 20Gi
  storageClassName: alibabacloud-cnfs-nas
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
        ports:
        - containerPort: 80
        volumeMounts:
          - name: nas
            mountPath: /nas-data
          - name: oss
            mountPath: /oss-data
          - name: disk
            mountPath: /disk-data
      volumes:
        - name: nas
          persistentVolumeClaim:
            claimName: pvc-nas 
        - name: disk  
          persistentVolumeClaim:
            claimName: pvc-disk
        - name: oss
          persistentVolumeClaim:
            claimName: pvc-oss
---
apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec: slb.s1.small
  name: nginx-svc
  namespace: default
spec:
  externalTrafficPolicy: Local
  internalTrafficPolicy: Cluster
  ipFamilies:
    - IPv4
  ports:
    - name: nginx
      nodePort: 31463
      port: 8080
      protocol: TCP
      targetPort: 80
  selector:
    app: nginx
  type: LoadBalancer

Procedure

image

Before migration, ensure that the reclaim policy for NAS, OSS, or disk volumes is Retain.

Step 1: Create a NAS mount target in the new VPC

Create a mount target based on the type of NAS volume that is used by the backup cluster.

  • If the NAS volume is managed by CNFS and uses the alibabacloud-cnfs-nas StorageClass, you must obtain the actual NAS file system ID managed by CNFS. When you restore the CNFS-managed NAS volume, you must also restore the CNFS instance and the corresponding StorageClass.

  • If the NAS volume is mounted by using static provisioning or dynamic provisioning with a custom StorageClass, you must create a new mount target for the NAS file system, and then create the StorageClass or volume in the restore cluster.

CNFS-managed NAS volumes

  1. In the backup cluster, run the following command to obtain information about the CNFS instance.

    kubectl get cnfs -o=custom-columns=name:.metadata.name,filesystemId:.status.fsAttributes.filesystemId

    Expected output:

    name                                         filesystemId
    cnfs-nas-c529e33c3f8704e27a8e2abff********   1caa64****

    If multiple CNFS instances are returned, create a new mount target for the NAS file system of each instance.

  2. Log on to the NAS console to add a mount target for the NAS file system. Make sure to select the VPC where the restore cluster resides, and select any vSwitch that is used by the cluster. For more information, see Create a mount target.

    Note
    • ECS instances that are in the same VPC but different vSwitches can access the NAS file system through this mount target.

    • A single General-purpose or Extreme NAS file system supports only two mount targets. Reclaim idle mount targets promptly.

  3. Find the target file system on the File System List page and click Manage, then click Mount Targets on the File System Details page, and then in the Mount Target column of the Mount Target list, hover over the imageIcon to view and record the mount target address.

  4. Refer to the following YAML to create a CNFS instance in the recovery cluster. Replace server with the mount target address that you recorded in the previous step. For more information about the parameters, see Manage NAS file systems by using CNFS.

    apiVersion: storage.alibabacloud.com/v1beta1
    kind: ContainerNetworkFileSystem
    metadata:
      name: cnfs-nas-restore-from-c529e33c3f8704e27a8e2abff********  
    spec:
      description: cnfs-nas
      parameters:
        server: 1caa64****-h****.cn-beijing.nas.aliyuncs.com # The mount target address of the NAS file system.
        storageType: Capacity  # Capacity-type NAS file system.
      reclaimPolicy: Retain
      type: nas
  5. (Optional) Delete the alibabacloud-cnfs-nas StorageClass that is created by default when you create the cluster, so you can recreate it in the next step.

    Note

    To reuse the original NAS volume, if you selected Create default NAS file system and dynamic StorageClass for CNFS when you created the restore cluster, you must delete the StorageClass before you can recreate the alibabacloud-cnfs-nas StorageClass.

     kubectl delete sc alibabacloud-cnfs-nas
  6. Use the following YAML template to create a StorageClass in the restore cluster.

    The containerNetworkFileSystem is created in the preceding Step 4, and the other configurations are the same as those of the default alibabacloud-cnfs-nas.

    allowVolumeExpansion: true
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: alibabacloud-cnfs-nas 
    mountOptions:
    - nolock,tcp,noresvport
    - vers=3
    parameters:
      archiveOnDelete: "false"
      # The name of the CNFS instance that you just created.
      containerNetworkFileSystem: cnfs-nas-restore-from-c529e33c3f8704e27a8e2abff********
      path: /
      volumeAs: subpath
    provisioner: nasplugin.csi.alibabacloud.com
    reclaimPolicy: Delete
    volumeBindingMode: Immediate

Static and custom dynamic provisioning

  1. Log on to the NAS console to add a mount target for the NAS file system. Make sure to select the VPC where the restore cluster resides, and select any vSwitch that is used by the cluster. For more information, see Create a mount target.

    Note
    • ECS instances that are in the same VPC but different vSwitches can access the NAS file system through this mount target.

    • A single General-purpose or Extreme NAS file system supports only two mount targets. Reclaim idle mount targets promptly.

  2. Recreate the volume or StorageClass in the restore cluster based on the mount type of the original NAS volume in the backup cluster.

    • Static mounting: You can rebuild the PVC and PV in the recovery cluster by using a new NAS mount target. For example, in the YAML configuration file for the original NAS PV, you only need to replace the server field with the new NAS mount target created in the new VPC. You do not need to modify the PVC configuration.

      apiVersion: v1
      kind: PersistentVolume
      metadata:
        name: pv-nas
        labels:
          alicloud-pvname: pv-nas
      spec:
        capacity:
          storage: 5Gi
        accessModes:
          - ReadWriteMany
        csi:
          driver: nasplugin.csi.alibabacloud.com
          volumeHandle: pv-nas   # Must be the same as the PV name.
          volumeAttributes:
            server: "2564f4****-ysu87.cn-shenzhen.nas.aliyuncs.com"
            path: "/csi"
        mountOptions:
        - nolock,tcp,noresvport
        - vers=3
    • Dynamic mounting: You can recreate the StorageClass in the recovery cluster by using a new NAS mount target. For example, the following is the YAML configuration file for the original NAS StorageClass. You only need to replace the server field with the NAS mount target created in the new VPC. You do not need to modify the PVC configuration.

      allowVolumeExpansion: true
      apiVersion: storage.k8s.io/v1
      kind: StorageClass
      metadata:
        name: alicloud-nas-subpath
      mountOptions:
      - nolock,tcp,noresvport
      - vers=3
      parameters:
        volumeAs: subpath
        server: "0cd8b4a576-g****.cn-hangzhou.nas.aliyuncs.com:/k8s/"
      provisioner: nasplugin.csi.alibabacloud.com
      reclaimPolicy: Retain

Step 2: Migrate NAS and OSS volumes

  1. In the backup cluster, add labels to the NAS and OSS PVCs and PVs to back up these resources based on the labels.

    kubectl label pvc pvc-nas pvc-oss backup="true"
    kubectl label pv `kubectl get pvc -l backup="true" | grep Bound | awk '{print $3}'| xargs` backup="true"
  2. Add labels to the NAS PVC and PV resources to modify the mount target configurations in a batch based on the labels.

    kubectl label pvc pvc-nas nas-volume="true"
    kubectl label pv `kubectl get pvc -l nas-volume="true" | grep Bound | awk '{print $3}'| xargs` nas-volume="true"
  3. In the backup cluster, create an application backup task for the NAS and OSS volumes. For more information, see the "Back up applications on demand" section of Create a backup plan or back up applications on demand.

    Important

    For example, Label is set to backup=true, Specify Resources is set to pvc,pv, and Volume Backup is set to Disabled (This means that only the YAML definition of the volume is backed up. The restored application then accesses the original data source across VPCs by using a new mount target, so you do not need to back up the volume data.).

    • On the Application Backup page, on the Backup Records tab, if the Status of the backup record is Completed, the backup is successful.

    • On the Application Backup page, on the Backup Records tab, click the name of the backup record to view its details. The following example indicates that all NAS and OSS volumes are backed up.

      {
        "v1/PersistentVolume": [
          "nas-916c0c04-e91e-4fc3-9115-d8a9********", # This NAS PV is dynamically provisioned.
          "pv-oss"
        ],
        "v1/PersistentVolumeClaim": [
          "default/pvc-nas",
          "default/pvc-oss"
        ]
      }
  4. Use the following YAML template to create a ConfigMap in the restore cluster. Then, use the Resource Modifier feature to modify the NAS mount target information.

    Note
    • To use the Resource Modifier feature, make sure that the migrate-controller component of the backup center is version 1.8.2 or later, and that you have cluster RBAC administrator permissions. For information about how to upgrade components, see Manage components. For information about cluster RBAC administrator authorization, see Use RBAC to authorize operations on cluster resources.

    • In the following YAML example, the original NAS volume uses the default alibabacloud-cnfs-nas StorageClass. If you mount NAS volumes by using dynamic provisioning with a custom StorageClass or static provisioning, adjust the ConfigMap based on your actual PVC and PV content.

    apiVersion: v1
    data:
      modifier: |
        version: v1
        resourceModifierRules:
        - conditions:
             groupResource: pvcs
             labelSelector:
                matchLabels:
                   nas-volume: "true"
          patches:
          - operation: replace
            path: "/spec/storageClassName"
            value: "alibabacloud-cnfs-nas" 
        - conditions:
             groupResource: pods
             labelSelector:
                matchLabels:
                   nas-volume: "true"
          patches:
          - operation: replace
            path: "/spec/csi/volumeAttributes/containerNetworkFileSystem"
            value: "cnfs-nas-restore-from-c529e33c3f8704e27a8e2abff********"
          - operation: replace
            path: "/spec/storageClassName"
            value: "alibabacloud-cnfs-nas"
          - operation: remove
            path: "/spec/csi/volumeAttributes/storage.kubernetes.io/csiProvisionerIdentity"
    kind: ConfigMap
    metadata:
      name: <backup-task-name>-resource-modifier
      namespace: csdr
  5. (Optional) Use the following backuplocation.yaml example to initialize the backup vault in the restore cluster. If it is already initialized, you can skip this step.

    apiVersion: csdr.alibabacloud.com/v1beta1
    kind: BackupLocation
    metadata:
      name: <name-of-the-backup-vault-for-backup>
      namespace: csdr
    spec:
      backupSyncPeriod: 0s
      # The following configurations must be consistent with the configurations used when the backup vault was created. You can also initialize it with one click in the restore cluster console.
      config:
        network: internal
        region: <region-of-the-OSS-bucket-for-the-backup-vault>
      objectStorage:
        bucket: <name-of-the-OSS-bucket-for-the-backup-vault>
        prefix: <subpath-in-the-OSS-bucket-for-the-backup-vault>
      provider: alibabacloud
  6. In the restore cluster, run the following command to confirm that the backup has been synchronized.

    kubectl get -ncsdr applicationbackup <backup-name>

    A non-empty output indicates that the backup has been synchronized.

  7. Use the following applicationrestore.yaml example to create a restore task in the restore cluster.

    Note

    Operations related to the advanced Resource Modifier feature can be performed only by using the command-line interface (CLI).

    apiVersion: csdr.alibabacloud.com/v1beta1
    kind: ApplicationRestore
    metadata:
      name: nas-oss-restore
      namespace: csdr
    spec:
      backupName: <backup-task-name>
      resourceModifier:
        kind: ConfigMap
        name: <backup-task-name>-resource-modifier
    kubectl apply -f applicationrestore.yaml
  8. Confirm that the restore task is in the Completed state. In the restore cluster, verify that the PVCs and PVs are fully restored and in the Bound state, and that the required fields are updated.

Step 3: Migrate disk volumes

When you create an on-demand backup in the console and select to back up volume data, only mounted volumes are backed up by default.

  1. Use the following applicationbackup.yaml example to create a data backup for all disk volumes in the backup cluster.

    apiVersion: csdr.alibabacloud.com/v1beta1
    kind: ApplicationBackup
    metadata:
      annotations:
      # If the backup vault is already in use in the cluster, you can omit this annotation.
      # csdr.alibabacloud.com/backuplocations: >-
        # {"name":"<backup-vault-name>","region":"<region-of-the-associated-bucket>","bucket":"<associated-bucket-name>","prefix":"<subpath-in-the-associated-bucket>","provider":"alibabacloud"}
      name: backup-disk
      namespace: csdr
    spec:
      # includedNamespaces: # List of namespaces to back up. All volumes (including disk and non-disk volumes) in these namespaces are backed up. Mutually exclusive with pvcList.
      # - default 
      backupType: PvBackup
      pvBackup:
        defaultPvBackup: true
        pvcList:  # List of PVCs to back up. If specified, the namespace-level selection is invalid.
        - name: pvc-disk 
          namespace: default
      storageLocation: <backup-vault-name>
      ttl: 720h0m0s
  2. In the backup cluster, run the following command to deploy the applicationbackup object.

    kubectl apply -f applicationbackup.yaml
  3. In the backup cluster, run the following command to check the status of the on-demand backup task.

    kubectl describe applicationbackup <yourApplicationBackupName> -n csdr

    Expected output:

    ...
    Status:
      Completion Timestamp:  2022-12-05T15:02:35Z
      Expiration:            2023-01-04T15:02:25Z
      Message:               success
      Phase:                 Completed

    The immediate backup task is created successfully when its status changes from Inprogress to Completed.

  4. In the restore cluster, confirm that the backup has been synchronized to the restore cluster. A non-empty output is expected.

    kubectl get -ncsdr applicationbackup <backup-name>
  5. Use the following applicationrestore.yaml example to create a restore task in the restore cluster.

    apiVersion: csdr.alibabacloud.com/v1beta1
    kind: ApplicationRestore
    metadata:
      name: disk-restore
      namespace: csdr
    spec:
      backupName: <backup-task-name>
    kubectl apply -f applicationrestore.yaml
  6. Confirm that the restore task is in the Completed state. In the restore cluster, verify that the PVCs and PVs are fully restored and in the Bound state, and that the disk ID in the volume has been updated.

Step 4: Configure overwrite policies for Services and Ingresses

The nginx-svc Service created in the backup cluster uses a load balancer created by CCM and has the following annotation and label:

Annotation:

service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec: slb.s1.small

Label:

service.k8s.alibaba/loadbalancer-id: lb-2ze2hxgbuw145******

This indicates that the Service uses the SLB instance whose ID is lb-2ze2hxgbuw145******. To reuse this instance in the restore cluster, create a Service annotation overwrite policy by using the following YAML template:

apiVersion: v1
data:
  # use-nlb: "true" takes effect only when you create a new load balancer.
  default.nginx-svc: | 
    {"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id":"lb-2ze2hxgbuw145******","xxx":"yyy"}
  # <ns>.<svc>
  # {"xxx": "yyy", ...} 
kind: ConfigMap
metadata:
  name: service-annotation-overwrite
  namespace: csdr

While other existing annotations for the Service can be kept or adjusted, change the service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec annotation to service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id.

  • For more information about annotations, see Configure a Classic Load Balancer (CLB) by using annotations and Configure a Network Load Balancer (NLB) by using annotations.

  • The overwrite policy replaces all existing annotations. You can also use this feature to create a new load balancer.

  • By default, a reused SLB instance does not forcibly overwrite its existing listeners. When the service.beta.kubernetes.io/alibaba-cloud-loadbalancer-force-override-listeners annotation is not configured, it defaults to false. We recommend that you switch the traffic only after you verify that the application in the restored cluster has started successfully.

Note

You can achieve a similar overwrite effect on an Ingress resource by creating ingress-annotation-overwrite.

Step 5: Migrate non-volume resources

Note

To modify backed-up cluster resources during application restoration, see Modify backed-up cluster resources during application restoration.

  1. In the backup cluster, back up the applications that you want to migrate. Do not select Back up Volume Data. For more information, see the "Back up applications on demand" section of Create a backup plan or back up applications on demand.

  2. In the backup cluster, on the Application Backup page, go to the Backup Records tab and confirm that the status of the backup task is Completed.

  3. In the restore cluster, wait for the backup to be synchronized, then restore the backup. For more information, see Restore an application.

  4. In the restore cluster, on the Application Backup page, click View Restoration Records and confirm that the status of the restore task is Completed.

  5. In the restore cluster, go to the Deployments page and confirm that the Nginx application has started and mounted the previously restored volumes. On the application details page, click the details of the nginx-svc Service and confirm that the Service reuses the existing SLB instance.

Related documents