我可以自动执行Google Cloud SDK gcloud init - 交互式命令

che*_*rba 26 gcloud google-cloud-sdk gcloud-cli

有关Google Cloud SDK的文档https://cloud.google.com/sdk/docs/gcloud init在安装后指示其运行.

有没有办法自动执行此步骤,因为这gcloud init是一个交互式命令?

che*_*rba 41

一个人不需要跑gcloud init.主要目标是确保配置凭据并且可能设置了项目属性.如果您拥有服务帐户凭据,则可以配置gcloud并准备好通过

gcloud auth activate-service-account --key-file=credential_key.json
gcloud config set project my-project
Run Code Online (Sandbox Code Playgroud)

为了完整性,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 regsions列表获取区域列表
  6. (可选)为gsutil创建默认配置文件
    • gcloud compute regions list