Google Container Engine: Accessing Cloud Storage

▼魔方 西西 提交于 2019-12-02 07:22:26

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/37926671/google-container-engine-accessing-cloud-storage

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