除了手动使用gcloud init
之外,我如何使用cli命令将当前运行的项目更改为GCP(Google Cloud Platform)帐户中的另一个项目?
gcloud projects list
将列出正在我的帐户上运行的项目。 我希望使用cli命令将当前项目更改为列表中的任何其他项目。
除了手动使用gcloud init
之外,我如何使用cli命令将当前运行的项目更改为GCP(Google Cloud Platform)帐户中的另一个项目?
gcloud projects list
将列出正在我的帐户上运行的项目。 我希望使用cli命令将当前项目更改为列表中的任何其他项目。
我更喜欢使用别名,对于那些可能需要根据项目需求执行多个命令的事情,我更喜欢使用函数...
例如
function switchGCPProject() {
gcloud config set project [Project Name]
// if you are using GKE use the following
gcloud config set container/cluster [Cluster Name]
// if you are using GCE use the following
gcloud config set compute/zone [Zone]
gcloud config set compute/region [region]
// if you are using GKE use the following
gcloud container clusters get-credentials [cluster name] --zone [Zone] --project [project name]
export GOOGLE_APPLICATION_CREDENTIALS=path-to-credentials.json
}
运行以下命令以查看可用项目:gcloud projects list
。这将给出您可以访问的项目列表。
要在项目之间切换,请运行:gcloud config set project <project-id>
。
另外,我建议在更改gcloud配置之前检查活动配置。您可以通过运行以下命令来执行:gcloud config list
#获取项目列表 gcloud projects list
#然后设置您想要切换到的项目ID,并运行以下命令
gcloud config set project $MY_PROJECT_ID
gcloud config set project <Project-ID>
Cloud CLI
项目将会改变,当前选中的项目会以黄色高亮显示。
--project <Project-ID>
gcloud config configurations activate <congif-name>
。gcloud init
我将别名添加到.bash_aliases文件中,以便切换到不同的项目。
alias switch_proj1="gcloud config set project ************"
gcloud projects list | awk '{print "alias switch_proj=\"gcloud config set project " $1 "\""}'
通过运行gcloud config list命令检查您的项目,然后运行gcloud config set "project name"命令设置项目名称。
只需使用 gcloud projects list
获取您拥有的项目。获取项目的 PROJECT_ID 以便使用。
然后使用 gcloud set project --project=PROJECT_ID
来设置项目。
要将现有项目更新为另一个项目,您可以使用以下命令行:
gcloud projects update PROJECT_ID --name=NAME
NAME:将是您的项目的新名称。
gcloud配置设置项目<PROJECT_ID>