我能自动化Google Cloud SDK gcloud init交互式命令吗?

35

Google Cloud SDK的文档https://cloud.google.com/sdk/docs/指导用户在安装后运行gcloud init

既然gcloud init是交互式命令,有没有自动化这一步骤的方法?

1个回答

65

不需要运行gcloud init命令。主要目的是确保凭据已配置,可能还设置了项目属性。如果您有服务帐号凭据,则可以通过以下方式配置并准备好使用gcloud:

gcloud auth activate-service-account --key-file=credential_key.json
gcloud config set project my-project

为了完整性,gcloud init 实际上执行以下步骤:

  1. 选择配置(以下之一)
    • gcloud config configurations create my_configuration
    • gcloud config configurations activate my_configuration
  2. 设置凭据(以下之一)
    • (交互式) gcloud auth login
    • gcloud config set account my_existing_credentials
    • gcloud auth activate-service-account
  3. 设置项目
    • gcloud config set project my_project
      • 可通过 gcloud projects list 查看设置凭证后可以访问的项目列表
  4. (可选) 设置默认 GCE 区域(必须启用 Compute API)
    • gcloud config set compute/zone my_default_gce_zone
      • 可通过 gcloud compute zones list 获取区域列表
  5. (可选) 设置默认 GCE 地区(必须启用 Compute API)
    • gcloud config set compute/region my_default_gce_region
      • 可通过 gcloud compute regions list 获取地区列表
  6. (可选) 为 gsutil 创建默认配置文件
    • gsutil config -n -o ~/.boto

可以使用凭证密钥文件中的project_id吗? - Some Name

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接