gcloud: Match cluster and compute zone

10/4/2019

Sometimes, I run into the following issue:

gcloud config list
[compute]
zone = us-central1-b
[container]
cluster = my-awesome-cluster
[core]
account = pkaramol@stackoverflow.com
disable_usage_reporting = False
project = some-nice-project


Your active configuration is: [default]
(.venv)
~/Workspace/sail-cli  4_bug_multiple_clusters ✗                                                                                                     5h28m ⚑
k get nodes
NAME                                           STATUS   ROLES    AGE     VERSION
gke-nodepool1-443c46af-mhmw   Ready    <none>   7h27m   v1.12.7-gke.25
gke-nodepool1-da892b44-8440   Ready    <none>   7h27m   v1.12.7-gke.25

Then for example I want to describe one instance (for some reason):

➢  gcloud compute instances describe gke-nodepool1-443c46af-mhmw
ERROR: (gcloud.compute.instances.describe) Could not fetch resource:
 - The resource 'projects/some-nice-project/zones/us-central1-b/instances/gke-nodepool1-443c46af-mhmw' was not found

I guess this happens because by default, the above command performs an inquiry within the zone set here:

[compute]
zone = us-central1-b

Is there a way to set the above zone to match the gke cluster's zone?

-- pkaramol
gcloud
google-cloud-platform
google-compute-engine
google-kubernetes-engine

2 Answers

10/4/2019

You can change your default zone with this command

gcloud config set compute/zone <zone>

But if you have 2 clusters, each is different zones, nothing is magic. You will have to change manually your zone before requesting the resource.

-- guillaume blaquiere
Source: StackOverflow

10/4/2019
gcloud config set compute/zone <zone>

You can also unset the default:

gcloud config unset compute/zone

Or pass a --zone parameter to the instance command:

gcloud compute instances describe --zone <zone> gke-nodepool1-443c46af-mhmw
-- robsiemb
Source: StackOverflow