首页 > 解决方案 > 将 GCP 服务帐户密钥传递给 GKE pod

问题描述

我在 TF ( 0.11.14) 中创建了一个 GCP 角色,将其附加到服务帐户,并为后者创建了一个密钥,如下所示:

resource "google_service_account_key" "my_service_account_key" {
  service_account_id = "${google_service_account.my_service_account.id}"
}

然后我private_key通过以下方式将 as 输出:

output "my_service_account_private_key" {
  value       = "${google_service_account_key.my_service_account_key.private_key}"
  sensitive   = true
}

这给我打印了一个很长的字符串,例如

ewogICJK49fo34KFo4 .... 49k92kljg==

假设该角色具有允许对 GCS 存储桶进行读/写的权限,我如何将上述凭证/私钥传递给(GKE)吊舱/部署,以便吊舱被授予特定的服务帐户(因此能够执行相应的权限允许什么,例如读取/写入存储桶)?

标签: google-cloud-platformgoogle-kubernetes-enginegoogle-iam

解决方案


您的主要步骤是

  1. 创建服务帐户。
  2. 为您的服务帐户提供必要的角色以使用 GCS 存储桶。
  3. 将帐户密钥另存为 Kubernetes Secret。
  4. 使用服务帐户配置和部署应用程序。

我相信你已经涵盖了第 1 步和第 2 步。我研究了两个示例(1、2 ,它们可能对其余步骤有所帮助。


推荐阅读