GCP:如何从 VM 实例访问云存储桶
GCP: how to access cloud storage bucket from a VM instance
我正在尝试在 GCP VM 实例中部署 运行 一个 docker 映像。
我需要它来访问某个云存储桶(读写)。
如何在 VM 中安装存储桶?如何在我的 VM 中的 Docker 容器 运行ning 中安装存储桶?
我已经阅读 google 云文档有一段时间了,但我仍然感到困惑。所有指南都展示了如何从本地计算机访问存储桶,而不是如何将其安装到 VM。
https://cloud.google.com/storage/docs/quickstart-gsutil
找到了一些关于 Fuse 的信息,但仅将单个存储桶安装到 VM 文件系统看起来过于复杂。
Google Cloud Storage 存储桶无法安装在 Google 没有第三方软件(例如 FUSE)的计算实例或容器中。 Linux 和 Windows 都没有内置的云存储驱动程序。
Google Cloud Storage 是对象存储 API,它不是文件系统。因此,它并不是真正设计为在 VM 中 "mounted"。它被设计为高度耐用和可扩展到非常大的对象(和大量对象)。
尽管您可以将 gcsfuse to mount it as a filesystem, that method has pretty significant drawbacks. For example, it can be expensive in operation count to do even simple operations 用于普通文件系统。
同样,有很多 surprising behaviors 这是因为它是一个对象存储。例如,您不能编辑对象——它们是不可变的。为了给人一种写入对象中间的错觉,实际上,只要调用 close()
或 fsync()
发生,对象就会被删除并重新创建。
使用 GCS 的最佳方法是将您的应用程序设计为使用 the API (or the S3 compatible API) directly. That way the semantics are well understood by the application, and you can optimize for them to get better performance and control your costs. Thus, to access it from your docker container, ensure your container has a way to authenticate through GCS (either through the credentials on the instance, or by deploying a key for a service account 并具有访问存储桶的必要权限),然后让应用程序直接调用 API。
最后,如果您实际上需要的是一个文件系统,而不是特定的 GCS,Google 如果您需要一个专为该特定用例设计的大型可挂载文件系统,Cloud 确实提供了至少 2 个其他选项:
- Persistent Disk, which is the baseline filesystem that you get with a VM, but you can mount many of these devices on a single VM. However, you can't mount them read/write to multiple VMs at once -- if you need to mount to multiple VMs, the persistent disk must be read only 对于它们安装到的所有实例。
- Cloud Filestore 是一种托管服务,它在永久性磁盘前面提供 NFS 服务器。因此,文件系统可以挂载 read/write 并在多个 VM 之间共享。然而,它比 PD 贵得多(在撰写本文时,大约 0.20 美元/GB/month 与
us-central1
中的 0.04 美元/GB/month),并且有最小大小要求 (1TB)。
我正在尝试在 GCP VM 实例中部署 运行 一个 docker 映像。 我需要它来访问某个云存储桶(读写)。
如何在 VM 中安装存储桶?如何在我的 VM 中的 Docker 容器 运行ning 中安装存储桶?
我已经阅读 google 云文档有一段时间了,但我仍然感到困惑。所有指南都展示了如何从本地计算机访问存储桶,而不是如何将其安装到 VM。 https://cloud.google.com/storage/docs/quickstart-gsutil
找到了一些关于 Fuse 的信息,但仅将单个存储桶安装到 VM 文件系统看起来过于复杂。
Google Cloud Storage 存储桶无法安装在 Google 没有第三方软件(例如 FUSE)的计算实例或容器中。 Linux 和 Windows 都没有内置的云存储驱动程序。
Google Cloud Storage 是对象存储 API,它不是文件系统。因此,它并不是真正设计为在 VM 中 "mounted"。它被设计为高度耐用和可扩展到非常大的对象(和大量对象)。
尽管您可以将 gcsfuse to mount it as a filesystem, that method has pretty significant drawbacks. For example, it can be expensive in operation count to do even simple operations 用于普通文件系统。
同样,有很多 surprising behaviors 这是因为它是一个对象存储。例如,您不能编辑对象——它们是不可变的。为了给人一种写入对象中间的错觉,实际上,只要调用 close()
或 fsync()
发生,对象就会被删除并重新创建。
使用 GCS 的最佳方法是将您的应用程序设计为使用 the API (or the S3 compatible API) directly. That way the semantics are well understood by the application, and you can optimize for them to get better performance and control your costs. Thus, to access it from your docker container, ensure your container has a way to authenticate through GCS (either through the credentials on the instance, or by deploying a key for a service account 并具有访问存储桶的必要权限),然后让应用程序直接调用 API。
最后,如果您实际上需要的是一个文件系统,而不是特定的 GCS,Google 如果您需要一个专为该特定用例设计的大型可挂载文件系统,Cloud 确实提供了至少 2 个其他选项:
- Persistent Disk, which is the baseline filesystem that you get with a VM, but you can mount many of these devices on a single VM. However, you can't mount them read/write to multiple VMs at once -- if you need to mount to multiple VMs, the persistent disk must be read only 对于它们安装到的所有实例。
- Cloud Filestore 是一种托管服务,它在永久性磁盘前面提供 NFS 服务器。因此,文件系统可以挂载 read/write 并在多个 VM 之间共享。然而,它比 PD 贵得多(在撰写本文时,大约 0.20 美元/GB/month 与
us-central1
中的 0.04 美元/GB/month),并且有最小大小要求 (1TB)。