Google集装箱引擎:访问云端存储 [英] Google Container Engine: Accessing Cloud Storage

查看:160
本文介绍了Google集装箱引擎:访问云端存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得在Google集装箱引擎中运行的应用程序默认凭据。该文档表示它们适用于App Engine和Compute Engine,但我已被告知应将其透明地传递到在Container Engine上运行的容器。



以下是失败的代码:

  credentials = GoogleCredentials.get_application_default()
service = discovery.build('storage' ,'v1',credentials = credentials)

错误是: AssertionError:没有为服务memcache找到api代理



希望应用程序默认凭据与Container Engine一起使用是否正确?如果没有,任何人都可以推荐从Container Container上运行的容器连接到云端存储的正确方法?



谢谢。



编辑:运行 gcloud beta auth application-default activate-service-account --key-file< my_key> .json 上述Python示例中的凭据对象填充数据。但是我仍然遇到同样的错误。

解决方案

在Container Engine上访问云存储的最简单的方法似乎是< a href =https://googlecloudplatform.github.io/gcloud-python/stable/ =nofollow> gcloud 库。



它如果App Engine SDK安装在容器上(gcloud找到并假定它在App Engine上运行),则不会使用零配置。所以我停止使用官方的 Google容器



python容器上,只需添加 gcloud requires.txt (或运行 pip install gcloud )。只要容器位于Google Compute Engine实例上,您可以访问同一个项目中的任何一个桶。



示例:


$ b $来自gcloud import storage的
$ b $ = $。
bucket = client.get_bucket('< bucket_name>')
blob = bucket.blob('test_file.txt')
blob.upload_from_string('test content')

gcloud库也适用于 Java Node Ruby


I can't get the Application Default Credentials working in Google Container Engine. The docs say that they're intended for App Engine and Compute Engine, but I've been told that they should transparently pass through to a container running on Container Engine.

Here's the code that's failing:

credentials = GoogleCredentials.get_application_default()
service = discovery.build('storage', 'v1', credentials=credentials)

The error it's failing with: AssertionError: No api proxy found for service "memcache"

Is it correct to expect Application Default Credentials to work with Container Engine? If not, can anyone recommend the proper way to connect to cloud storage from a container running on Container Engine?

Thanks.

EDIT: After running gcloud beta auth application-default activate-service-account --key-file <my_key>.json the credentials object in the above Python example is populated with data. However I'm still getting the same error.

解决方案

The easiest way to access cloud storage on Container Engine appears to be the gcloud library.

It won't work with zero configuration if the App Engine SDK is installed on the container (gcloud finds it and assumes it's running on App Engine). So I stopped using the official Google container.

On a python container just add gcloud to your requirements.txt (or run pip install gcloud). As long as the container lives on a Google Compute Engine instance you can access any bucket in the same project.

Example:

from gcloud import storage
client = storage.Client()
bucket = client.get_bucket('<bucket_name>')
blob = bucket.blob('test_file.txt')
blob.upload_from_string('test content')

The gcloud library also exists for Java, Node, and Ruby.

这篇关于Google集装箱引擎:访问云端存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆