返回
Featured image of post GCP - gcloud config 設定配置使用

GCP - gcloud config 設定配置使用

gcloud 基本使用

gcloud,這是操作GCP的CLI工具,安裝方式很簡單,google官方手把手安裝

一般來說如果你有不只一個專案或帳號控制,會有一堆的登入設定要設定 這樣就會需要多個config要處理,每一次又要改地區/地域/專案/帳號 建議可以先把這些帳號直接放進配置列表

配置列表 gcloud config configurations list

> gcloud config configurations list
NAME      IS_ACTIVE  ACCOUNT                  PROJECT     COMPUTE_DEFAULT_ZONE  COMPUTE_DEFAULT_REGION
default   False      [email protected]      xxxxx       asia-east1-a          asia-east1

切換配置 gcloud config configurations create [name]

> gcloud config configurations create personal
Created [personal].
Activated [personal].
> gcloud config configurations list
NAME      IS_ACTIVE  ACCOUNT                  PROJECT     COMPUTE_DEFAULT_ZONE  COMPUTE_DEFAULT_REGION
default   False      [email protected]      xxxxx       asia-east1-a          asia-east1
personal  True

接下來就可以設定這個設定列表的相關設定:

  1. 帳號登入 - gcloud auth login
  2. 設定專案 - gcloud config set project [project name]
  3. 設定地區 - gcloud config set compute/zone [zone name]
  4. 設定地域 - gcloud config set compute/region [region name]

切換配置 gcloud config configurations activate [name]

> gcloud config configurations list
NAME      IS_ACTIVE  ACCOUNT                  PROJECT     COMPUTE_DEFAULT_ZONE  COMPUTE_DEFAULT_REGION
default   False      [email protected]      xxxxx       asia-east1-a          asia-east1
personal  True       [email protected]      ccccc       asia-east1-a          asia-east1
> gcloud config configurations activate default
Activated [default].
> gcloud config configurations list
NAME      IS_ACTIVE  ACCOUNT                  PROJECT     COMPUTE_DEFAULT_ZONE  COMPUTE_DEFAULT_REGION
default   True       [email protected]      xxxxx       asia-east1-a          asia-east1
personal  False      [email protected]      ccccc       asia-east1-a          asia-east1

刪除配置 gcloud config configurations delete [name]

> gcloud config configurations delete personal
Deleted [personal].
The following configurations will be deleted:
 - personal
Do you want to continue (Y/n)?  Y
> gcloud config configurations list
NAME      IS_ACTIVE  ACCOUNT                  PROJECT     COMPUTE_DEFAULT_ZONE  COMPUTE_DEFAULT_REGION
default   True       [email protected]      xxxxx       asia-east1-a          asia-east1
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus