44

I am very new to Google Cloud. I was able to setup a wordpress site and am working on it now. However, it appears that my vm instance is using the following asia-east1-a for its zone. I was able to change the Region and Zone using gcloud commands with the following output:

$ gcloud config list compute/region 
Your active configuration is: [default]
[compute]
region = us-east4

$ gcloud config list compute/zone
Your active configuration is: [default]
[compute]
zone = us-east4-b

How does one change the active default to the new set zone? I would like my instance to run in the North East Coast of the USA?

Thanks, T

Rot-man
  • 18,045
  • 12
  • 118
  • 124
Tamer Ziady
  • 613
  • 1
  • 5
  • 10

5 Answers5

58

Use commands below at cloud shell.

To check your preferred region:

$ gcloud compute regions list

To change compute regions, I select us-east4 region:

$ gcloud config set compute/region us-east4

Updated property [compute/region].

$ gcloud config list compute/region 

[compute]

region = us-east4

In a similar way, you can change compute/zone.

Dave Liepmann
  • 1,555
  • 1
  • 18
  • 22
Aditya Sharma
  • 581
  • 4
  • 2
11
  • As described here, project-info metadata can be added per project to specify the default regions and zones. This is used only at the time of initializing gcloud (using gcloud init).

  • In addition, gcloud supports locally setting the default region and zone using the compute/region and compute/zone configurations (which is what you seem to have added to your local gcloud config). When these properties are set, they will override any configuration set in the project-info.

  • Since you have set these properties according to your requirements, I think your defaults are set as long as you're using that gcloud configuration.

  • Do remember that you can always override the zone and region using the --zone and --region arguments to any of the gcloud commands.

Moving instance from one zone to another

Changing the default zone/region does not move any of the existing VMs to a new zone. If you wish to move a VM from one zone to another, you can take a snapshot of the persistent disks, launch a new instance in the desired zone using the snapshot and cleanup the resources used by the original VM.

You can do this using either gcloud or follow a set of steps manually to achieve the same result.

gcloud compute instances move INSTANCE_NAME --zone SOURCE_ZONE --destination-zone DESTINATION_ZONE

In detail, Compute Engine will:

  • Take snapshots of persistent disks attached to the source instance.
  • Create copies of the persistent disks in the destination zone.
  • For instances moving within the same region, temporarily promote any ephemeral external IP addresses assigned to the instance to a static external IP address.
  • Create a new instance in the destination zone.
  • Attach the newly created persistent disks to your new instance.
  • Assign an external IP address to the new instance. If necessary, demote the address back to an ephemeral external IP address.
  • Delete the snapshots, original disks, and original instance.

If you want to manually move your instance, you can also perform these steps by hand.

Tuxdude
  • 47,485
  • 15
  • 109
  • 110
  • k, so the settings that I have changed are correct. Do I have to restart the VM or initiate a move or anything? Without losing the work / setup that I have already done? Do I just clone it to the new region and zone? I am very sorry if this seems obvious as I am very new to GCloud. Thanks, T – Tamer Ziady Jul 16 '17 at 11:12
  • Added info about moving an instance from one zone to another. – Tuxdude Jul 16 '17 at 16:39
  • K, I think I am close. I was able to run the command; however, it failed with: ERROR: (gcloud.compute.instances.move) Instances belonging to subnetworks cannot be moved interregionally. I have tried to change / delete the subnet (I do not care about internal or external IP - this instance is not in use yet and I can update DNS later). But it will not let me delete any subnet or change anything under networking? Any ideas? PS: Thank you so much for helping out... – Tamer Ziady Jul 16 '17 at 19:15
  • 5
    @Tuxdude what about that case : `Instance is a UEFI-enabled instance and does not support MoveInstance.` ? – user2284570 May 23 '20 at 19:28
  • 5
    This method did not work for me. I also returned an error `Instance is a UEFI-enabled instance and does not support MoveInstance.` – rocksNwaves Jul 22 '20 at 22:01
4

If you don't remember the specific commands, another option is to change the region and zone in the gcloud configurations file which is located in:

~/.config/gcloud/configurations/config_default

And contain the structure below:

[core]
account = my-account@my-domain
project = my-project

[compute]
zone = asia-south1-a
region = asia-south1

After changing region to us-central-1 you'll get the following output:

gcloud config list compute/region
[compute]
region = us-central1

gcloud config configurations list
NAME     IS_ACTIVE  ACCOUNT               PROJECT     COMPUTE_DEFAULT_ZONE  COMPUTE_DEFAULT_REGION
default  True       my-account@my-domain  my-project  us-central1-a         us-central1

Reference to all GCP regions and zones.

Rot-man
  • 18,045
  • 12
  • 118
  • 124
2

Create Image of the existing instance and after create a new instance with a new zone who you like and uploaded this image with you create before

VASO
  • 21
  • 2
0
gcloud compute instances move INSTANCE_NAME --destination-zone=DESTINATION_ZONE [--async] [--zone=ZONE] [GCLOUD_WIDE_FLAG …]

gcloud compute instances move facilitates moving a Compute Engine virtual machine from one zone to another.

EXAMPLE :

gcloud compute instances move compute-instance-1 --zone us-central1-b --destination-zone us-central1-f
Tiago Medici
  • 1,944
  • 22
  • 22