kubernetes - 在 GKE 中使用独立的 'gsutil'

标签 kubernetes google-kubernetes-engine service-accounts gsutil

我正在尝试使用独立的 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/

相关文章:

kubernetes - 如何防止 kube-dns 将请求转发到 8.8.8.8 :53

kubernetes - 确保GCE/GKE上的XFS卷

python-3.x - 我可以通过 Kubernetes API 获取 Pod 的暂停容器 ID 吗?

kubernetes - kubectl 命令标志值的大小写敏感

google-compute-engine - 已删除 Compute Engine 默认服务帐号

docker - 在 kubernetes 上运行的 Postgres 在 Pod 重建或集群重启时丢失数据

google-cloud-platform - GCP 负载均衡器或 Kubernetes 类型 = LoadBalancer

google-cloud-firestore - GCP : How to grant a role to a service account on a Firestore collection?

python - 通过域范围委派模拟用户的服务帐户访问 Google Sheets API 失败

google-analytics - 使用服务帐户进行Google Analytics(分析)报告