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
Related
I am new to google cloud. I have seen the similar question but I couldn't understand the answer. It will be great if someone could give easy instruction to tackle this problem.
I have two linux VM instances under same project on google cloud. I want to copy files from one VM to other VM.
I tried copy-files command. It threw error "deprecated, use scp instead"
I tried "gcloud compute scp user#vm2_instance_name:vm2_instance_file_path"
other answers say use "service account". I read about them and created one and created key as well in .json format but not sure what to do after that. Appreciate any suggestions.
If you are in one instance, don't worry about Google Cloud. Simply perform a scp to copy file from VM to another one.
If you don't have customize users on the VM, you can omit it
scp <my local file path> <vm name>:<destination path>
About service account, if your VM are in Google Cloud, they have the compute engine service account by default <projectNumber>-compute#developer.gserviceaccount.com
You can customize this service account if you want. This service account is mandatory to identify the VM which perform API call or gcloud command
Google's documentation addresses this. Personally, I have always preferred using gcloud compute scp as it provides both a simplistic way of performing transfers while not necessarily taking away any of the complexities and features that other transferring options provide.
In any case, in the documentation provided you will most likely find the method that are more in-line with what you want.
This is the solution that worked for me:
1. gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE
INTERNAL_IP EXTERNAL_IP STATUS
instance-1 us-central1-a n2-standard-8
10.128.0.60 34.66.177.187 RUNNING
instance-2 us-central1-a n1-standard-1
10.128.15.192 34.69.216.153 STAGING
2. gcloud compute ssh instance-1 --zone=us-central1-a
3. user#instance-1:~$ ls
myfile
4. usernstance-1:~$ gcloud compute scp myfile user#instance-2:myfile
5. gcloud compute ssh instance-2 --zone=us-central1-a
6. user#instance-2:~$ ls
myfile
I'm now learning Google Cloud Platform instance creation. As part of learning, trying to launch RHEL 6 instance on a f1.micro instance-type in us-east1-b region.
Here's is the Gcloud command I've used:
gcloud compute --project=<project-id> instances create cldinit-vm --zone=us-east1-b --machine-type=f1-micro--subnet=default --network-tier=PREMIUM --metadata-from-file startup-script=initscript.sh --maintenance-policy=MIGRATE --service-account=<account-id>#developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --min-cpu-platform="Intel Broadwell" --tags=http-server --image=rhel-6-v20181210 --image-project=rhel-cloud --boot-disk-size=10GB --boot-disk-type=pd-standard --boot-disk-device-name=cldinit-vm --labels=name=cloudinit-vm
When I run the command, it is showing the error below,
ERROR: (gcloud.compute.instances.create) Could not fetch resource:
- Invalid value for field 'resource.machineType': 'https://www.googleapis.com/compute/v1/projects/<project-id>/zones/us-east1-b/machineTypes/f1-micro--subnet=default'.
Machine type with name 'f1-micro--subnet=default' does not exist in zone 'us-east1-b'.
I've two questions:
I could not modify the Subnet settings from "default", as it is the only option available to choose from "network" in instance launching page.
So could anyone help to resolve the issue please?
Since I'm learning GCP, I've launched the CLI command into "CloudShell" directly from the link located at bottom of GCP compute engine - instance launching page.
Is there a correction needs to be done from "Google" to provide the working command ?
As part of learning, found that there was a missing space in between the option value f1-micro and --subnet.
So here is the corrected command snippet
gcloud compute --project=<project-id> instances create cldinit-vm --zone=us-east1-b --machine-type=f1-micro --subnet=default ....
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.
I have an instance that I can upgrade and downgrade machine type from gcloud command. For example, I can do
gcloud compute instances set-machine-type instance-name --machine-type f1-micro
to downgrade an existing instance and
gcloud compute instances set-machine-type ubuntu --machine-type n1-standard-1
to upgrade the machine type. But I need to also attach an GPU when I upgrade. I can do that on web interface but I need to do this on command line.
It's possible to attach a GPU from API but looks like it's not possible to detach one after attaching.
Here's how to attach a GPU to an existing instance.
POST https://www.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/ubuntu/setMachineResources
{
"guestAccelerators": [
{
"acceleratorType": "https://www.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/acceleratorTypes/nvidia-tesla-k80",
"acceleratorCount": 1
}
]
}
Here's the reference to the feature request to made for detaching a GPU.
https://issuetracker.google.com/65267943
Currently, it is not possible to attach GPU to an existing instance using "gcloud" command. You can attach GPU using cloud console, "EDIT" option of the instance when it is in the stop state. Another way to attach GPU to an existing instance (stopped) is through API [1][2].
Following is the URL syntax which needs to be defined for property guestAccelerators[].acceleratorType:
https://www.googleapis.com/compute/beta/projects/project-id/zones/zone-where-instance-is-deployed/acceleratorTypes/nvidia-tesla-k80
Example:
https://www.googleapis.com/compute/beta/projects/test-project/zones/us-west1-b/acceleratorTypes/nvidia-tesla-k80
[1] https://developers.google.com/apis-explorer/#search/compute%20engine/compute/v1/compute.instances.setMachineResources
[2] https://cloud.google.com/compute/docs/reference/beta/instances/setMachineResources
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
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.
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.
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.
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
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