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
接下來就可以設定這個設定列表的相關設定:
- 帳號登入 -
gcloud auth login
- 設定專案 -
gcloud config set project [project name]
- 設定地區 -
gcloud config set compute/zone [zone name]
- 設定地域 -
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