Exporting storage to persistent volumes

In order for a workload to run independent of Migrate for Anthos components, you need to export its storage to a standalone PersistentVolume (PV).

In this topic, you will finalize the migration to GKE by moving your workload's PVs to Compute Engine Persistent Disk using the Migrate for Anthos storage exporter.

Prerequisites

Determine the volume size of your container before continuing. To do so, calculate the total size of disks to be migrated with the source VM. We recommend an additional margin of 15-25% to accommodate for future growth. For example, a 16 GB volume could have a size of 20 GB.

Configure your YAML

The YAML below defines a new object for each of the following:

---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: gce-pd-ssd-intree
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-ssd
  replication-type: none

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  # Replace this with the name of your application
  name: gce-pd-claim-suitecrm-app
spec:
  storageClassName: gce-pd-ssd-intree
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20G # Replace this with your target volume size

---
# Storage Exporter configuration:

apiVersion: v1
kind: ConfigMap
metadata:
  name: exporter-sample-config
  namespace: exporter
data:
  config: |-
    appSpec:
      dataFilter:
        - "- *.swp"
        - "- /etc/fstab"
        - "- /boot/"
        - "- /tmp/"

---
# Storage Exporter Jobs

apiVersion: batch/v1
kind: Job
metadata:
  name: exporter-sample-suitecrm-app
  namespace: exporter
spec:
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "false"
        anthos-migrate.gcr.io/action: export
        anthos-migrate.gcr.io/source-type: vlsdisk
        anthos-migrate.gcr.io/source-pvc: csi-vlsdisk-suitecrm-app #the PVC of your existing disk
        anthos-migrate.gcr.io/target-pvc: gce-pd-claim-suitecrm-app
        anthos-migrate.gcr.io/config: exporter-sample-config
    spec:
      restartPolicy: OnFailure
      containers:
      - name: exporter-sample
        image: anthos-migrate.gcr.io/v2k-export:v0.9.6

After configuring your YAML, delete the StatefulSet that is holding onto the existing volumes. Don't worry, you will recreate it after the export completes.

kubectl delete statefulset [APPLICATION_NAME]

Apply the YAML to run the export jobs.

kubectl apply -f [JOB-YAML]

GKE will run the jobs. To check on their status, use kubectl get jobs. In the example below, the job's name is exporter-sample-suitecrm-app.

kubectl get jobs
NAME                           DESIRED   SUCCESSFUL   AGE
exporter-sample-suitecrm-app   1         0            11s

Once the jobs are marked as SUCCESSFUL, reconfigure the StatefulSet to reference the exported PV.

Running containers with exported storage

The YAML file below recreates the StatefulSet of the application above to use the exported storage.

---
kind: StatefulSet
apiVersion: apps/v1beta1
metadata:
  name: suitecrm-app
  namespace: default
spec:
  serviceName: "suitecrm-app-svc"
  replicas: 1
  selector:
    matchLabels:
      app: suitecrm-app
  template:
    metadata:
      labels:
        app: suitecrm-app
      annotations:
        anthos-migrate.gcr.io/action: run
        anthos-migrate.gcr.io/source-type: exported
        anthos-migrate.gcr.io/source-pvc: gce-pd-claim-suitecrm-app
    spec:
      containers:
      - name: suitecrm-app
        image: anthos-migrate.gcr.io/v2k-run:v0.9.6

Apply the YAML to launch your containers:

kubectl apply -f [EXPORTED-YAML]

Deleting streaming storage PVCs

The PersistentVolumeClaim that streamed storage to the container is no longer needed. You can delete it.

Run the following command, setting [SOURCE_PVC] to the value of anthos-migrate.gcr.io/source-pvc above.

kubectl delete pvc [SOURCE_PVC]

After this step, your workload is ready to run independently of both the source VM and Migrate for Anthos components.

Was this page helpful? Let us know how we did:

Send feedback about...

Migrate for Anthos Documentation