Share a persistent disk between Google Compute Engine VMs

a 夏天 提交于 2019-12-17 15:46:08

问题


From Google's documentation:

It is possible to attach a persistent disk to more than one instance. However, if you attach a persistent disk to multiple instances, all instances must attach the persistent disk in read-only mode. It is not possible to attach the persistent disk to multiple instances in read-write mode.

If you attach a persistent disk in read-write mode and then try to attach the disk to subsequent instances, Google Compute Engine returns an error.

So, I need to have a share persistent-disk as frontend for all my compute engine, good, how can you write on this shared disk?

My guess (I hope) is a read/write persistent-disk can be attached only with 1 compute engine but this same disk can be share in read only to others VMs, is thats right?

Lets say I have 2 Compute Engine VMs and 2 persistent disks, is this flow is possible?

  • compute1 read/write disk1 and read only disk2
  • compute2 read/write disk2 and read only disk1

回答1:


No, this is not possible, as the documentation that you cited at the time of writing said (since updated):

However, if you attach a persistent disk to multiple instances, all instances must attach the persistent disk in read-only mode.

The documentation has been re-arranged since then; the new docs are at a different URL but with the same content:

You can attach a non-root persistent disk to more than one virtual machine instance in read-only mode, which allows you to share static data between multiple instances. Sharing static data between multiple instances from one persistent disk is cheaper than replicating your data to unique disks for individual instances.

If you attach a persistent disk to multiple instances, all of those instances must attach the persistent disk in read-only mode. It is not possible to attach the persistent disk to multiple instances in read-write mode. If you need to share dynamic storage space between multiple instances, connect your instances to Cloud Storage or create a network file server.

If you have a persistent disk with data that you want to share between multiple instances, detach it from any read-write instances and attach it to one or more instances in read-only mode.

which means you cannot have one instance have write access while another has read-only access.

If you want to share data between them, you need to use something other than Persistent Disk. Below are some possible solutions.

You can use any of the following hosted/managed services:

  • Google Cloud Filestore — perhaps closest to what you're looking for, as it provides an NFSv3 file system
    • You can also use Elastifile on GCP as a fully-managed service; note that GCP acquired Elastifile in July 2019
  • Google Cloud Datastore
  • Google Cloud Storage, which you can use via the GCS API (JSON or XML) or you can mount it using gcsfuse as a block device
  • Google Cloud Bigtable
  • Google Cloud SQL

Alternatively, you can run your own:

  • self-managed Elastifile storage deployment (for fully-managed, see previous section for the link)
  • database (whether SQL or NoSQL)
  • distributed filesystem such as Ceph, GlusterFS, OrangeFS, ZFS, etc.
  • file server such as NFS or SAMBA
  • single VM as a data storage node, and use sshfs to create a FUSE mount from other VMs that want to access that data



回答2:


GCP has alpha functionality for 'multi-write' persistent disks. It's been in alpha for quite a long time so who knows if it'll make it to beta or ga any time soon. Here is a link to the documentation. https://cloud.google.com/sdk/gcloud/reference/alpha/compute/disks/create#--multi-writer



来源:https://stackoverflow.com/questions/26910960/share-a-persistent-disk-between-google-compute-engine-vms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!