Exporting an NFS file share to a persistent disk

You can copy data from an NFS file share to a Compute Engine Persistent Disk. This can be useful when your migrated VM may have used the file share, but the file share wasn't migrated because it was external to the migrated VM. Copying the data to a location closer to your migrated VMs can reduce latency once your VMs are migrated.

Migrate for Anthos includes a utility for copying the data from its source volume to a destination. The example in this topic copies an NFS Persistent Volume to a Compute Engine persistent disk. The examples here borrow from existing object definitions (as noted below), using a native source type available with the included utility.

See Exporting storage to persistent volumes for information on using the included utility to export data from migration short-term storage to long-term storage at the conclusion of migration.

Configure and apply the copy operation

Use the following steps to create YAML that defines data source and destination, as well as the export action. You can copy the following YAML examples into individual files that you apply separately, or into a single file that you apply once.

  1. Define the Persistent Volume and Persistent Volume Claim that represent the source file store to copy from.

    This configuration is based on a similar one you'll find describe in Accessing Fileshares from Google Kubernetes Engine Clusters.

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: [FILESERVER]
    spec:
      capacity:
        storage: [STORAGE]
      accessModes:
      - ReadWriteMany
      nfs:
        path: /[FILESHARE]
        server: [IP_ADDRESS]
    

    where:

    • [FILESERVER] is a name of your choice.
    • [STORAGE] is the size of the fileshare.
    • [FILESHARE] is the name of the fileshare.
    • [IP_ADDRESS] is the IP address for the fileshare.
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: [FILESERVER_PVC_NAME]
      namespace: default
    spec:
      accessModes:
      - ReadWriteMany
      storageClassName: ""
      resources:
        requests:
          storage: [STORAGE]
    

    where:

    • [FILESERVER_PVC_NAME] is a name of your choice.
    • [STORAGE] is the size of the fileshare.
  2. Define the Persistent Volume Claim that will create destination Compute Engine persistent disk.

    kind: StorageClass
    apiVersion: storage.k8s.io/v1
    metadata:
      name: [STORAGE_CLASS_NAME]
    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: [TARGET_PVC_NAME]
      namespace: default
    spec:
      storageClassName: [STORAGE_CLASS_NAME]
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: [TARGET_STORAGE]
    

    where:

    • [STORAGE_CLASS_NAME] is a name of your choice.
    • [TARGET_PVC_NAME] is a name of your choice for the target volume claim.
    • [TARGET_STORAGE] is the target volume size.
  3. Add a ConfigMap definition to specify the locations and types of data to copy.

    dataFilter is a Migrate for Anthos field through which you can filter paths and files copied from the source PVC. In this example, preceding the paths and files listed with a minus sign specifies that each item in the list should be excluded from the copy. For example, the following excludes the /etc/fstab directory:

    "- /etc/fstab"
    
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: [CONFIGMAP_NAME]
      namespace: default
    data:
      config: |-
        appSpec:
          dataFilter:
            - "- *.swp"
            - "- /etc/fstab"
            - "- /boot/"
            - "- /tmp/"
    

    where:

    • [CONFIGMAP_NAME] is a name of your choice for the config map.
  4. Add a Job object to define the export action that will copy data from the source PVC to the target PVC.

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: [JOB_NAME]
      namespace: default
    spec:
      template:
        metadata:
      name: [JOB_NAME]
      namespace: default
    spec:
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject: "false"
            anthos-migrate.gcr.io/action: export
            anthos-migrate.gcr.io/source-type: native
            anthos-migrate.gcr.io/source-pvc: [FILESERVER_PVC_NAME]
            anthos-migrate.gcr.io/target-pvc: [TARGET_PVC_NAME]
            anthos-migrate.gcr.io/config: [CONFIGMAP_NAME]
        spec:
          restartPolicy: OnFailure
          containers:
          - name: exporter-sample
            image: anthos-migrate.gcr.io/v2k-export:v1.0.1
    

    where:

    • export is the action to take.
    • native is the source type.
    • [JOB_NAME] is a name of your choice for the job.
    • [FILESERVER_PVC_NAME] is the name you chose for the source Persistent Volume Claim.
    • [TARGET_PVC_NAME] is the name you chose for the target Persistent Volume Claim.
    • [CONFIGMAP_NAME] is the name you chose for the config map.
  5. Apply the object definitions above to begin the copy operation.

    kubectl apply -f job-yaml
    

Verify a successful copy

You can verify that the copy successfully occurred by attaching both the source and destination Persistent Volume to a pod.

  1. Using a Pod definition such as the following:

    apiVersion: v1
    kind: Pod
    metadata:
      name: [POD_NAME]
      namespace: default
    spec:
      containers:
      - name: nfs
        image: ubuntu
        command: ["/bin/bash", "-ec", "while :; do echo '.'; sleep 5 ; done"]
        volumeMounts:
        - mountPath: /nfs
          name: nfs-server
        - mountPath: /nfs-pd
          name: exported-nfs-server
      volumes:
      - name: nfs-server
        persistentVolumeClaim:
          claimName: [FILESERVER_PVC_NAME]
      - name: exported-nfs-server
        persistentVolumeClaim:
          claimName: [TARGET_PVC_NAME]
    

    where:

    • [POD_NAME] is a name of your choice for the pod.
    • [FILESERVER_PVC_NAME] is a name of your choice.
    • [TARGET_PVC_NAME] is the name you chose the target Persistent Volume Claim.
  2. Verify that both sources are connected by listing files from both locations.

    • List files on the source NFS file share:

      ls /nfs
      

      Note the list of files:

      file1  file2  file3  lost+found
      
    • List files on the destination persistent disk:

      ls /nfs-pd
      

      Note that the list of files is that same as for the source:

      file1  file2  file3  lost+found