×
Community Blog The Flexvolume Scenario Disk Migration Solution

The Flexvolume Scenario Disk Migration Solution

This article explains the flexxvolume scenario disk migration solution with application examples.

By Kan Junbao

Overview

If you deploy an application in Alibaba Cloud Container Service and use disk data volumes to save data, you may have data migration, data rollback, and disk type change requirements. This solution provides a disk Data Management solution in clusters, running Flexvolume and Disk-Controller.

It is suitable for the following scenarios:

  • Disk Rotation: You previously used ESSD disks and want to rotate them to SSDs (or vice versa.)
  • Disk Rotation: You previously used encrypted disks and want to rotate them to non-encrypted disk disks (or vice versa.)
  • Cross-Zone Migration: You previously used disks in zone A and want to use them in zone B.
  • Cross-Region Migration: You previously used disks in the Hangzhou Region, and you want to use them in the Beijing Region.
  • Data Rollback: If your disk is regularly snapped, you want to use a snapshot of a certain version to restore data.

The general principle of the solution is to use disk snapshot technology to implement data rollback, migration, and configuration change and maintain data consistency.

Sample Application

Create a StatfulSet application and attach a disk. The template is listed below:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql
spec:
  serviceName: "mysql"
  replicas: 3
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        command: ["sh", "-c"]
        args: ["sleep 10000"]
        volumeMounts:
        - name: ssd
          mountPath: /data
  volumeClaimTemplates:
  - metadata:
      name: ssd
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "alicloud-disk-ssd"
      resources:
        requests:
          storage: 20Gi

Create the preceding application and write the validation data:

# kubectl get pod
mysql-0                       1/1     Running   0          6m40s
mysql-1                       1/1     Running   0          72s
mysql-2                       1/1     Running   0          65s

# kubectl get pvc
ssd-mysql-0    Bound    d-2ze48olpbvnlpofw9wpi   20Gi       RWO            alicloud-disk-ssd   7m3s
ssd-mysql-1    Bound    d-2ze6sw4nc3n9ovquss0s   20Gi       RWO            alicloud-disk-ssd   95s
ssd-mysql-2    Bound    d-2zeddogm2wsjovoch45m   20Gi       RWO            alicloud-disk-ssd   88s

# kubectl exec -ti mysql-0 touch /data/mysql0
# kubectl exec -ti mysql-1 touch /data/mysql1
# kubectl exec -ti mysql-2 touch /data/mysql2

# kubectl exec -ti mysql-0 ls /data
lost+found  mysql0
# kubectl exec -ti mysql-1 ls /data
lost+found  mysql1
# kubectl exec -ti mysql-2 ls /data
lost+found  mysql2

Disk Type Conversion Scenario

In the preceding MySQL instance, three pods use three SSD disks. We use rotation to change the three disks to the ESSD type, but the data is consistent. The rotation process includes:

  • Separating multiple disks into snapshots
  • Creating new PVCs and PVs from snapshots
  • The names of PVCs and PVs must comply with the new StatefulSet naming rules.

Step 1: Create a Snapshot

Find the disk IDs from the PV information corresponding to the three pods and go to the ECS console to create the disk snapshots.

Assume the three disk snapshot IDs are:

  • pod-0 -> ssd-mysql-0 -> d-2ze48olpbvnlpofw9wpi -> s-2zeh66llz43m8g65y4um
  • pod-1 -> ssd-mysql-1 -> d-2ze6sw4nc3n9ovquss0s -> s-2zegk0d8ne75tz0g15zd
  • pod-2 -> ssd-mysql-2 -> d-2zeddogm2wsjovoch45m -> s-2zec3gco02of30dt6lgb

Step 2: Create a New PVC

The old PVC template is listed below:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ssd-mysql-0
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
  storageClassName: alicloud-disk-ssd

Create a new PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    provider.disksnapshot.aliyuncs.com/disk-snapshot-id: s-2zeh66llz43m8g65y4um
  name: essd-mysql-0
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
  storageClassName: alicloud-disk-essd

Changes include:

1) Change the name to "essd-mysql-0"

2) Add annotations and the value is pod-0,pvc-0 the corresponding disk snapshot ID

3) storageClassName to alicloud-disk-essd

Create a PVC:

# kubectl apply -f pvc-0.yaml
essd-mysql-0   Bound    d-2ze1nxm8hrcdmktxuocn   20Gi       RWO            alicloud-disk-essd   18m

Similarly, create the pvc-1:essd-mysql-1,pvc-2:essd-mysql-2:

essd-mysql-1   Bound    d-2zeh66llz43m8tzeminq   20Gi       RWO            alicloud-disk-essd   2m27s
essd-mysql-2   Bound    d-2ze383b6z44xjm79qoj2   20Gi       RWO            alicloud-disk-essd   2m25s

Step 3: Update the Application

Delete the old statefulset and create a new statefulset. The template is listed below:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql
spec:
  serviceName: "mysql"
  replicas: 3
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        command: ["sh", "-c"]
        args: ["sleep 10000"]
        volumeMounts:
        - name: essd
          mountPath: /data
  volumeClaimTemplates:
  - metadata:
      name: essd
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "alicloud-disk-ssd"
      resources:
        requests:
          storage: 20Gi

Compared with the old template, two places need to be modified:

1) The name in the volumeClaimTemplates is changed to ESSD

2) The name in volumeMounts is changed to ESSD

# kubectl get pod
mysql-0                       1/1     Running   0          58s
mysql-1                       1/1     Running   0          28s
mysql-2                       1/1     Running   0          23s

# kubectl describe pod mysql-0 |grep ClaimName
    ClaimName:  essd-mysql-0
# kubectl describe pod mysql-1 |grep ClaimName
    ClaimName:  essd-mysql-1
# kubectl describe pod mysql-2 |grep ClaimName
    ClaimName:  essd-mysql-2

# kubectl exec mysql-0 ls /data
lost+found mysql0

# kubectl exec mysql-1 ls /data
lost+found mysql1

# kubectl exec mysql-2 ls /data
lost+found mysql2

In summary, the cloud disk of the mysql 3 replica has been changed to the ESSD type using snapshot. Other scenario documents will be available later.

0 0 0
Share on

Alibaba Container Service

177 posts | 31 followers

You may also like

Comments

Alibaba Container Service

177 posts | 31 followers

Related Products