Container Service for Kubernetes (ACK) allows you to back up and restore stateful
applications deployed in an ACK cluster. This is an all-in-one solution to achieve
crash consistency, application consistency, and cross-region disaster recovery for
stateful applications in ACK clusters. This topic describes how to migrate applications
across clusters by using the application backup feature.
Prerequisites
Two Kubernetes clusters of the same version are created and the Kubernetes version
are 1.18 or later. For more information, see
Create an ACK managed cluster.
Introduction
In this example, a cluster named Cluster_A and another cluster named Cluster_B are
used. The following example shows how to back up an application in Cluster_A and restore
the application to Cluster_B.
Notice Make sure that the two clusters run the same Kubernetes version and the Kubernetes
version are 1.18 or later. Otherwise, you cannot migrate the application to the specified
cluster.

Procedure
- Grant the required Object Storage Service (OSS) permissions to Cluster_A and Cluster_B.
For more information, see Configure OSS permissions.
- Install the application backup component in Cluster_A and Cluster_B. For more information,
see Install the application backup component.
- Create the same backup vaults for Cluster_A and Cluster_B. When you create backup
vaults for Cluster_A and Cluster_B, select the same OSS bucket and set Network Type
to Public Network. For more information, see Create a backup vault.
- Create a backup task in Cluster_A. For more information, see Create a backup task.
After you create the backup task in Cluster_A, you can log on to Cluster_B to view
the backup task on the Backups and Snapshots tab of the Application Backup page.
- Create a snapshot in Cluster_B. For more information, see Create a snapshot.
If you enable Volume Backup and use storage other than disks to store data when you create the backup task, the
Hybrid Backup Recovery (HBR) service is used to store the data. In this case, you
must create a volume snapshot.
- On the Application Backup page, click the Restore tab and create a restoration task based on the backup task that you created in Cluster_A.
For more information, see Create a restoration task.
Example 1: Use the backup center feature to migrate WordPress applications across
ACK clusters
Install the WordPress application in a Kubernetes cluster and publish a blog post
on the WordPress website. Use disks to store the text content and use Apsara File
Storage NAS (NAS) file systems to store the images in the blog post. This way, both
disk volumes and NAS volumes are used to store the application data. Use the backup
center feature to back up the WordPress application in the source Kubernetes cluster.
Then, restore the application and application data to the destination Kubernetes cluster
and verify data and application integrity.
- In the cn-huhehaote region, create a managed Kubernetes cluster named Cluster_A and another managed Kubernetes
cluster named Cluster_B.
- Install the WordPress application in Cluster_A. For more information, see Deploy a WordPress application by using the Helm CLI.
On the
Parameters tab, select the
default namespace and replace
storageClass: "alicloud-disk-ssd"
with
storageClass: "alibabacloud-cnfs-nas"
, as shown in the following code block:
persistence:
enabled: true
## wordpress data Persistent Volume Storage Class
## If defined, storageClassName: <storageClass>
## If set to "-", storageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
## set, choosing the default provisioner. (gp2 on AWS, standard on
## GKE, AWS & OpenStack)
storageClass: "alibabacloud-cnfs-nas"
## If you want to reuse an existing claim, you can pass the name of the PVC using
## the existingClaim variable
# existingClaim: your-claim
accessMode: ReadWriteOnce
size: 20Gi
- Install the application backup component and create backup vaults in Cluster_A and
Cluster_B.
- Create a backup task in Cluster_A. For more information, see Create a backup task.
Back up the
default namespace.

After the
123backup-1 backup task changes to the
Completed state, you can view the backup task on the
Backups and Snapshots tab of the
Application Backup page in Cluster_B.
- On the Backups and Snapshots tab, find the 123backup-1 backup task and click Create Snapshot in the Actions column.
In the
Create Snapshot dialog box, select
alicloud-disk from the drop-down list in the
Change StorageClass column.

After the status of the related persistent volume claim (PVC) changes to
ConvertionCompleted, the snapshot is created.

- Create a restoration task named restore-123backup-1 in Cluster_B.
- Verify that the backup is restored.
- In the left-side navigation pane of the details page of Cluster_B, choose . Find the WordPress application, click Details in the Actions column, and then check whether the WordPress application is in the Running state.
- In the left-side navigation pane of the details page, choose
- On the Services page, find the Service that is created for the WordPress application and click the
hyperlink in the External Endpoint column. The WordPress homepage appears.
Example 2: Use the backup center feature to migrate MySQL applications from an external
Kubernetes cluster to an ACK cluster
Example description
- Create an external Kubernetes cluster. For example, create a Kubernetes cluster by
using Rancher. Then, register the external Kubernetes cluster in the ACK console and use a YAML
template to deploy the MySQL application and mount a local disk to the application.
- Create a managed Kubernetes cluster in the ACK console and deploy the application
backup component in the cluster.
- The cluster registration proxy uses the backup center feature to back up the MySQL
application and application data in the external Kubernetes cluster.
- Restore the MySQL application and application data to the ACK cluster in the cloud
by using the backup center feature.
Migrate steps
- Register the external Kubernetes cluster. For more information, see Create a cluster registration proxy and register an on-premises cluster.
- Use a kubectl client to connect to the registered Kubernetes cluster. For more information,
see Connect to ACK clusters by using kubectl.
- Create a persistent volume (PV), a PVC, and a MySQL application.
- Use the following template to create a file named mysql.yaml:
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-pv
spec:
capacity:
storage: 100Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
local:
path: /home/
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- for-rancher-k8s-cluster002
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: local-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
spec:
serviceName: "mysql"
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "mysql"
volumeMounts:
- name: local
mountPath: /var/lib/mysql
volumes:
- name: local
persistentVolumeClaim:
claimName: local-pvc
- Run the following command to deploy the PV, PVC, and MySQL application:
kubectl --kubeconfig rancher_huhehaote_kubeconfig apply -f mysql/mysql.yaml
- Run the following command to query the pod that runs the MySQL application:
kubectl --kubeconfig rancher_huhehaote_kubeconfig get pod
Expected output:
NAME READY STATUS RESTARTS AGE
mysql-0 1/1 Running 0 171m
- Run the following command to log on to the MySQL application. Create a database and
a table, and write test data in the MySQL application.
kubectl --kubeconfig rancher_huhehaote_kubeconfig exec -it mysql-0 sh
root@mysql-0:/# mysql -u root -pmysql
create database test;
create table student(id int, name varchar(20),age int);
insert into student values (1,2,3);
- Create a backup task in the registered Kubernetes cluster named Cluster_A. For more
information, see Create a backup task.
Back up the
default namespace.

After the
mysql-backup-111 backup task changes to the
Completed state, you can view the backup task on the
Backups and Snapshots tab of the
Application Backup page in Cluster_B.
- On the Backups and Snapshots tab, find the backup task named mysql-backup-111 and click Create Snapshot in the Actions column.
In the
Create Snapshot dialog box, select
alicloud-disk from the drop-down list in the
Change StorageClass column.

After the status of the related PVC changes to
ConvertionCompleted, the snapshot is created.

- Create a restoration task named restore-111 in Cluster_B.
- Verify that the backup is restored.
- Run the following command to query the pod that runs the MySQL application:
kubectl --kubeconfig rancher_online_kube -n mysql-111 get pod
Expected output:
NAME READY STATUS RESTARTS AGE
mysql-0 1/1 Running 0 37m
- Log on to the restored database and view the data.

The output indicates that the MySQL application and application data of the external
Kubernetes cluster are restored to the ACK cluster.