Mount a Filestore instance to Cloud TPU VMs

Filestore is a fully managed network attached storage (NAS) for Compute Engine. Filestore offers native compatibility with existing enterprise applications and supports any NFSv3-compatible client.

Before you begin

In order to mount a Filestore instance on your Cloud TPU VM, you need to add a Filestore role (Cloud Filestore Editor or Cloud Filestore Viewer) to the service account associated with your Cloud TPU VM. If you don't specify a custom service account when you create a Cloud TPU VM, your Cloud TPU VM uses the default Compute Engine service account. For more information about how to specify a service account when creating a Cloud TPU VM, see Set up the Cloud TPU environment. For more information about how to create a service account, see Create service accounts.

Add the Filestore Editor role to a service account

The following instructions show you how to add the Cloud Filestore Editor role to the Compute Engine default service account. You can follow these instructions to add the Cloud Filestore Editor role to any service account. You can search and use a custom service account instead of the Compute Engine default service account in step 2.

  1. Open the IAM console.

  2. Select the View by principals tab and type Name:Compute Engine default service account in the Filter field.

  3. Click next to the service account. The IAM console displays a dialog listing the roles assigned to the Compute Engine default service account.

  4. Click to add another role.

  5. Expand the Select a role drop down menu, type Filestore in the filter, and select Cloud Filestore editor.

  6. Click Save to dismiss the dialog. You have added the Filestore Editor role to the Compute Engine default service account.

For more information about service accounts, see Service Account Overview. To learn more about IAM roles, see Roles and permissions.

Create a Filestore instance

Create a Filestore instance using the instructions found in Creating Filestore instances.

Mount a Filestore instance on a Cloud TPU VM

The commands you use to mount a Filestore instance on a Cloud TPU depends on whether you are using a single Cloud TPU or a Cloud TPU Pod slice.

Mount a Filestore instance on a single Cloud TPU VM

  1. Connect to your Cloud TPU VM using SSH.
          gcloud compute tpus tpu-vm ssh your-tpu-name \
            --zone=your-zone
        
  2. Install the nfs-common package.
          sudo apt-get update --allow-releaseinfo-change \
            && sudo apt-get -y update \
            && sudo apt-get -y install nfs-common
        
  3. Create a directory in which to mount NFS
          sudo mkdir -p mount-dir \
            && sudo chmod ugo+rw mount-dir
        
  4. Find the IP address of the Filestore.
          gcloud filestore instances describe filestore-instance-name \ 
            --region filestore-region
        
  5. Mount Filestore instance on your Cloud TPU VM onto your mount directory.
          sudo mount filestore-ip:file-share-name mount-dir-name
        

Mount a Filestore instance on a Cloud TPU Pod slice

Cloud TPU Pod slices are composed of 2 or more Cloud TPU VMs. The following commands use the gcloud compute tpus tpu-vm ssh command with the --worker=all and --command flags to run the commands on all Cloud TPU VMs at one time.

  1. Install the nfs-common package on all Cloud TPU VMs in your Pod slice.
            gcloud compute tpus tpu-vm ssh your-tpu-name \
              --project=your-gcp-project \
              --zone=your-zone \
              --worker=all \
              --command="sudo apt-get update --allow-releaseinfo-change && sudo apt-get -y update && sudo apt-get -y install nfs-common"
          
  2. Create a directory in which to mount the Filestore instance. Replace mount-dir-name with a directory name of your choice.
          gcloud compute tpus tpu-vm ssh your-tpu-name \
            --project=your-gcp-project \
              --zone=your-zone \
              --worker=all \
              --command="sudo mkdir -p mount-dir-name && sudo chmod ugo+rw mount-dir-name"
          
  3. Find the IP address of the Filestore instance.
          gcloud filestore instances describe filestore-instance-name \ 
            --region filestore-region
        
  4. Mount Filestore instance on your Cloud TPU VM. Replace the following:
          sudo mount filestore-ip:file-share-name mount-dir
        

Writing data to Filestore instance

Make sure you grant Linux read and write permissions on the directory in which you mount the Filestore instance. You can use the directory as you would your local file system.