Having issues with a simple instance move in GCE.
Using the following commands in gcloud.
gcloud compute instances move MY-VM \ --zone europe-west1 --destination-zone europe-west2
gcloud compute instances move MY-VM --zone europe-west1-b --destination-zone europe-west2-b
gcloud compute instances move MY-VM \ --destination-zone europe-west2-b
gcloud compute instances move MY-VM \ europe-west1-b --destination-zone europe-west2-b
Gcloud throws the follwing error for above;
ERROR: (gcloud.compute.instances.move) unrecognized arguments:
--zone
europe-west1-b
Google --help documents:
NAME
gcloud compute instances move - move an instance and its attached
persistent disks between zones
SYNOPSIS
gcloud compute instances move INSTANCE_NAME
--destination-zone=DESTINATION_ZONE [--async] [--zone=ZONE]
[GCLOUD_WIDE_FLAG ...]
DESCRIPTION
gcloud compute instances move facilitates moving a Google Compute Engine
virtual machine from one zone to another. Moving a virtual machine may
incur downtime if the guest OS must be shutdown in order to quiesce disk
volumes prior to snapshotting.
For example, running:
$ gcloud compute instances move example-instance-1 \ --zone us-central1-b --destination-zone us-central1-f
will move the instance called example-instance-1 with its all attached
persistent disks, currently running in us-central1-b, to us-central1-f.
is it me or am I losing my mind.
If you want to move the instance within the same region, you can simply type the below command
gcloud compute instances move your_vm --destination-zone=zone_name
Let me know if that helps
String '\ --zone' gets parsed as argument ' --zone' with the leading space. There is no such argument for the command, there is only '--zone' without the leading space. That's why the command doesn't recognize the argument.
Couple of things:
A. Syntax is pretty nuanced here. I was able to duplicate the error you got, and the error doesn't have anything to do with the validity of the zone name.
B. It appears that there is a typo in the example in the help page. Here are variations that worked for me as I moved my VM back and forth between zones. I used my own zones because I didn't want to pay Europe rates:
1: entering everything on one line, with that backslash, just like the docs say (failure):
ingernet#merp:~> gcloud compute instances move MY-VM \ --zone us-west1-b --destination-zone us-west1-a
ERROR: (gcloud.compute.instances.move) unrecognized arguments:
--zone
us-west1-b
2: entering everything on one line, without the backslash (success):
ingernet#merp:~> gcloud compute instances move MY-VM --destination-zone us-west1-a --zone us-west1-b
Moving gce instance MY-VM...done.
3: entering the flags on a separate line (success, regardless of flag sequence):
ingernet#merp:~> gcloud compute instances move MY-VM \
> --zone us-west1-a --destination-zone us-west1-b
Moving gce instance MY-VM...done.
Notice how the 2nd example uses the \ character to escape the return key so that you can wrap your code onto another line in the interest of legibility.
The sequence of the flags doesn't matter, regardless of how many lines the command is entered on:
ingernet#merp:~> gcloud compute instances move MY-VM \
> --destination-zone us-west1-a --zone us-west1-b
Moving gce instance MY-VM...done.
I hope this helps. GCP is rad in a lot of ways but is not without its gotchas.
UPDATE:
The issue was that I was trying to change actual country so that was the issue. Trying to move from Belgium to London and the only way was to create a new instance using the snapshot of the one I wanted to move.
you can only move instances ie;
europe-west1-b to europe-west1-c or west1-a etc
Hope this helps.
Related
The following works great - creating VM from source image and additional persistent disk(s).
gcloud compute instances create ${INSTANCE_NAME} \
--image-project ${PROJECT_NAME} \
--image ${BASE_IMAGE_NAME} \
--zone=${ZONE_NAME} \
--create-disk=size=128GB,type=pd-balanced,name=${INSTANCE_NAME}-home,device-name=homedisk
The following, however, creates a VM BUT no additional disk(s) are created.
gcloud beta compute instances create ${INSTANCE_NAME} \
--source-machine-image ${BASE_IMAGE_NAME} \
--zone=${ZONE_NAME} \
--create-disk=size=128GB,type=pd-balanced,name=${INSTANCE_NAME}-homedisk,device-name=homedisk
The documentation for the command does not suggest that --source-machine-image and --create-disk cannot work in tandem. The property overrides when creating a VM from machine image suggests that any of the properties can be overridden.
Any insights as to what might be going on?
the problem here is with the --source-machine-image ${BASE_IMAGE_NAME} flag because your BASE_IMAGE_NAME must already have the desired additional disk, that is why it is not being created, because it is creating everything from the BASE_IMAGE_NAME which does not have an additional disk, try it by creating a new Machine image with the desired additional disk attached and then run your gcloud beta compute instances create again (the second command you have) and confirm that it creates the instance based on that Machine image including the additional disk.
If you need to create a new instance with 1 additional disk you should use (your first command) --image ${NAME} --image-project ${PROJECT}
So --source-machine-image and --image ... --image-project are very different.
Here is the documentation for Machine images which may explain this better.
https://cloud.google.com/compute/docs/machine-images
I'm working my way through GCP ACE material, and when creating a compute instance you can do the following:
gcloud compute instance create --machine-type=f1-micro mylovelyVM
This is all good, but I want to know how to override region and zone in the same command, I know I can just do config set the region and zone but would be nice to know if it's possible in the one line command.
I have tried the following to no avail :
gcloud compute instances create --machine-type=f1-micro mylovelyVM --region us-west2 --zone us-west2-b
gcloud compute instances create --region us-west2 --zone us-west2-b --machine-type=f1-micro mylovelyVM
I have tried variations on this.
I have been using the -h and --help commands to try and work out at what point to specify the region, but so far no luck.
Error message is --region (did you mean '--reservation'?) for every iteration, which leads me to think its not expecting --region flag at that point.
Documentation states the flow should be gcloud <global flags> <service/product> <group/area> <command> <flags> <parameters>
In which case the command should be
gcloud compute --region us-west2 --zone us-west2-b instances create --machine-type=f1-micro mylovelyVM
Is there a limit on chaining overrides or am I doing this wrong?
You create instances in zones not regions. Regions comprise multiple zones and, while some other services are regional, (compute engine) instances must be placed in zones.
So, use only --zone=.. and not --region=...
The documentation is good but gcloud compute instances create has many flags and so it can be confusing:
https://cloud.google.com/sdk/gcloud/reference/compute/instances/create
Using Cloud Console, you can try permutations of the command and, at the bottom, there's an option to have Console show you the equivalent REST or Cloud SDK (gcloud) command. This is helpful.
IMO, it is good practice to specify e.g. --zone, --project and other flags on the command-line rather than use config. It's more typing but it's more explicit and can avoid errors that result from implicit (assumed) values from config.
Best wishes for your learning!
Update
gcloud compute instances create mylovelyvm \
--zone=us-west2-b \
--machine-type=f1-micro \
--project=${PROJECT}
Created [https://www.googleapis.com/compute/v1/projects/${PROJECT}/zones/us-west2-b/instances/mylovelyvm].
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
mylovelyvm us-west2-b f1-micro 10.168.0.2 35.236.23.189 RUNNING
Marking Daz's answer as correct, though I did find a way without specifying project :
gcloud compute instances create my-lovelyVM --zone=us-west2-b --machine-type=f1-micro
How is the following possible?
➢ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
my-instance-1 us-east4-a n1-standard-8 10.16.22.11 RUNNING
my-instance-2 us-east4-a n1-standard-8 10.16.22.12 RUNNING
my-instance-3 us-east4-a n1-standard-8 10.16.22.13 RUNNING
(.venv)
~/Workspace/staging-env-configs workablestg9 ✔ 1h40m
➢ gcloud compute instances describe my-instance-1
ERROR: (gcloud.compute.instances.describe) Could not fetch resource:
- The resource 'projects/my-project/zones/us-central1-b/instances/my-instance-1' was not found
(.venv)
If your instance is running in your default zone "us-central1-b", you can simply do gcloud compute instances describe <instance-name> However, if your instance is not running in the defautl zone you have to provide the zone as well so you will do:
gcloud compute instances describe my-instance-1 --zone us-east4-a
If you look at the output: "The resource 'projects/my-project/zones/us-central1-b/instances/my-instance-1'" You can clearly see it's looking in your default zone us-central1-b
I am trying to create a backup snapshot of my GCP instance. However, every-time I create a snapshot and boot it up, the /home/ folder contents seem to be missing from my original instance.
Any idea why this is happening and how to fix it?
Could you give more details about the steps that you follow, to create the instance from the snapshot.
In my case I've used this commands and he have my home on the new instance:
gcloud compute --project=your-project-name disks snapshot disk_name_of_your_instance --zone=zone_of_your_instance --snapshot-names=name_of_your_snapshot
gcloud compute --project your-project-name disks create "your-new-instance" --size "10" --zone "us-central1-c" --source-snapshot "name_of_your_snapshot" --type "pd-standard"
gcloud beta compute --project=your-project-name instances create your-new-instance --zone=us-central1-c --machine-type=n1-standard-1 --subnet=your-subnet
I saw the following warning message when I connected to the compute engine:
"This zone is deprecated and will go offline soon. When the zone goes offline, all VMs in this zone will be destroyed.
In this case, my machine will be deleted, am I right? Shouldn't it be migrated online normally? How can I move my machine to a different zone?
Thanks.
UPDATE:
Google has released new tools in the sdk for moving instances and disks. First you need to update the group tools:
$ gcloud components update
Then you can move instances as follows:
$ gcloud compute instances move my-vm --zone europe-west1-a --destination-zone europe-west1-d
Or disks:
$ gcloud compute disks move my-disk --zone europe-west1-a --destination-zone europe-west1-d
ORIGINAL ANSWER:
You will need to migrate manually for zone deprecation
Source: https://cloud.google.com/compute/docs/zones#zone_deprecation
You can find instructions on migrating here: https://cloud.google.com/compute/docs/instances#moving_an_instance_between_zones