我正在尝试使用独立的 gsutil
GKE 集群中运行的容器中的工具,但我无法让它工作。我相信集群有足够的权限(见下文)。然而,运行
./gsutil ls gs://my-bucket/
产量
ServiceException: 401 Anonymous users does not have storage.objects.list access to bucket my-bucket.
我错过了什么吗?我没有
.boto
文件,因为我认为它不应该是必要的——或者是吗?这是集群和节点池具有的范围列表:- https://www.googleapis.com/auth/compute
- https://www.googleapis.com/auth/devstorage.full_control
- https://www.googleapis.com/auth/logging.write
- https://www.googleapis.com/auth/monitoring.write
- https://www.googleapis.com/auth/pubsub
- https://www.googleapis.com/auth/servicecontrol
- https://www.googleapis.com/auth/service.management.readonly
- https://www.googleapis.com/auth/trace.append
最佳答案
您可以使用 service account 在 GKE 上的 docker 容器内使用 gsutil ,或使用您自己的凭据。
服务帐号
1) 添加 service-account.json
文件到您的项目。
2) 添加 .boto
文件指向您的项目,指向 service-account.json
文件:
[Credentials]
gs_service_key_file = /path/to/service-account.json
3) 在您的 Dockerfile 中,设置
BOTO_CONFIG
指向此的环境变量 .boto
文件:ENV BOTO_CONFIG=/path/to/.boto
自己的凭据
1) 在本地,运行 gcloud auth login。一个
.boto
文件将在 ~/.config/gcloud/legacy_credentials/your@account.com/.boto 中创建,结构如下:[OAuth2]
client_id = <id>.apps.googleusercontent.com
client_secret = <secret>
[Credentials]
gs_oauth2_refresh_token = <token>
2) 复制此
.boto
文件到你的项目中3) 在您的 Dockerfile 中,设置
BOTO_CONFIG
指向此的环境变量 .boto
文件:ENV BOTO_CONFIG=/path/to/.boto
我使用 pip install gsutil 在 docker 容器中安装了独立的 gsutil
关于kubernetes - 在 GKE 中使用独立的 'gsutil',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44442354/