Using NBD, 9P, CIFS/Samba, and Ceph network file systems

This page describes using NBD, 9P, CIFS/Samba, and Ceph network file systems with Cloud Run.

If you are using NFS, Filestore, or Cloud Storage FUSE on Cloud Run refer to the following pages:

You can use NBD, 9P, CIFS/Samba, and Ceph network file systems to share and persist data between multiple containers and services in Cloud Run. This feature is only available if you are using the Cloud Run second generation execution environment.

If you need to read and write files in your Cloud Run service using these file system, you have several options:

  • If you don't need to persist the data beyond the lifetime of the instance, you can use the built-in memory file system.
  • If you need to persist data beyond instance lifetimes, and you want to use standard file system semantics, use NDB, 9P, CIFS/Samba, and Ceph network file systems with Cloud Run.
  • If you need to persist data beyond instance lifetimes, and you don't need standard file system semantics, the simplest option is to use Cloud Storage client libraries. This is also a good option if you need to access data from many instances at the same time.

Limitations

The following considerations apply to using NDB, 9P, CIFS/Samba, and Ceph network file systems on Cloud Run:

  • You must specify the second generation execution environment when you deploy to Cloud Run.

  • Cloud Run is designed to scale rapidly to a large number of instances. However, most network file systems are not designed for concurrent use by a large number of clients. Consider using the maximum instances feature to limit the number of Cloud Run instances.

Set up a network file system

If you don't already have a file server set up, follow the File servers on Compute Engine solution guide to select and set up the right file system for your needs. If you're using an existing file server, make sure it is accessible from a VPC network

Configure a Serverless VPC Access connector

You need to use Serverless VPC Access connector to connect your Cloud Run service to the VPC network where your network file system is running.

To create a Serverless VPC Access connector on the same VPC network to connect to the Cloud Run service, follow the instructions on the page Connecting to a VPC network.

Mount the file system from your Cloud Run service

To mount a network file system:

  1. Define a startup script that starts your application and specifies the mount point your Dockerfile, using the following examples, replacing the variables as needed:

    • For NBD

       echo "mounting ext4 image via NBD"
       nbd-client -L -name image IP_ADDRESS DEVICE_NAME
       mount DEVICE_NAME MOUNT_POINT_DIRECTORY

    • For PD-SSD via NBD

       echo "mounting PD-SSD via NBD"
       nbd-client -L -name disk IP_ADDRESS DEVICE_NAME
       mount DEVICE_NAME MOUNT_POINT_DIRECTORY

    • For 9P

       echo "mounting 9p export"
       mount -t 9p -o trans=tcp,aname=/mnt/diod,version=9p2000.L,uname=root,access=user IP_ADDRESS MOUNT_POINT_DIRECTORY

    • For SMB

       echo "mounting SMB public share"
       mount -t cifs -ousername=USERNAME,password=PASSWORD,ip=IP_ADDRESS //FILESHARE_NAME MOUNT_POINT_DIRECTORY
       echo "mounts completed"

  2. Define your environment configuration with the Dockerfile. You'll use RUN to specify any additional needed system package, such as nbd-client for NBD. Use CMD to specify the command to be executed when running the image (the startup script run.sh) and to provide default arguments for ENTRYPOINT, which specifies the init process binary.

Access a network file system from Cloud Run service code

To access the network file systems in your service code, use file read and write operations as you usually do.

Containerize and deploy

When your Cloud Run service code is complete, containerize, and deploy as you usually do for a Cloud Run service, making sure you specify the second generation execution environment.

What's next