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
Related
I have created a nfs-server using Google Cloud's FileStore and have linked it to a kubernetes engine. I would like to know how to access the stored data on FileStore?
Thanks, Look forward to the suggestions.
You can only get operation information using the gcloud tool. To use the gcloud tool, you must either install the Cloud SDK or use the Cloud Shell that is built into the Cloud Console.
You can get a list of Filestore operations by running the operations list command:
gcloud filestore operations list
--[project=project-id] \
--[zone=zone]
where:
project-id is the project ID of the Cloud project that contains the
Filestore instance. You can skip this flag if the Filestore instance
is in the gcloud default project. You can set the default project by
running:
gcloud config set project project-id
zone is the zone where the Filestore instance resides. Run the gcloud
filestore zones list command to get a list of supported zones. You
can skip this flag if the Filestore instance is in the gcloud default
zone. You can set the default zone by running:
gcloud config set filestore/zone zone
The command returns a response similar to the following example:
OPERATION_NAME LOCATION TYPE TARGET STATUS CREATE_TIME DURATION
operation-1505929956434-559a2a41c217c-231e6a94-a4b6a803 us-central1-c create nfs1 DONE 2017-09-20T17:52:36 <1S
operation-1505931180862-559a2ed176d0d-a0d70ae0-35ef2e71 europe-west1-b create nfs2 DONE 2017-09-20T18:13:00 <1S
You can get details of a specific Filestore operation by running the operations describe command:
gcloud filestore operations describe operation-name \
--[project=project-id] \
--[zone=zone]
where:
operation-name is the name of the Filestore operation. Use the
operations list command to get a list of operation names.
project-id is the project ID of the Cloud project that contains the
Filestore instance. You can skip this flag if the Filestore instance
is in the gcloud default project. You can set the default project by
running:
gcloud config set project project-id
zone is the zone where the Filestore instance resides. Run the gcloud
filestore zones list command to get a list of supported zones. You
can skip this flag if the Filestore instance is in the gcloud default
zone. You can set the default zone by running:
gcloud config set filestore/zone zone
The command returns a response similar to the following:
done: true
metadata:
'#type': type.googleapis.com/google.cloud.common.OperationMetadata
apiVersion: v1beta1
createTime: '2017-10-09T22:18:09.347400Z'
endTime: '2017-10-09T22:20:04.392199183Z'
target: projects/filestore-test/locations/us-central1-c/instances/filer3
verb: delete
name: projects/filestore-test/locations/us-central1-c/operations/operation-1507587489330-55b2490c4f394-faece090-1c0e16db
Getting operation information document: https://cloud.google.com/filestore/docs/getting-operation-information
Here is also how to monitor your Filestore instances and set up alerts for low disk space and low backups quota.
You can monitor Filestore instances using Cloud Monitoring.
I have two GCP projects, projectA and projectB. In projectB, I have a machine image B-machine-image. My goal was to make a copy of the machine image in projectA. But since there is no way to copy the machine image from projectB to projectA directly, I thought I can create a instance in projectA using the machine image in projectB, then use the new instance in projectA to create a machine image locally.
I found a Google Doc for this: https://cloud.google.com/compute/docs/machine-images/create-instance-from-machine-image and followed the steps to first grant the service account in projectA admin role to the machine image B-machine-image in projectB, then run the command to make the instance like:
gcloud beta compute instances create my-new-instance --project=projectA --zone us-central1-b --source-machine-image projects/projectB/global/machineImages/B-machine-image --service-account 123456789000-compute#developer.gserviceaccount.com
and I am getting the error:
ERROR: (gcloud.beta.compute.instances.create) Could not fetch resource:
Invalid value for field 'resource.networkInterfaces[0].network': 'projects/123456789000/global/networks/projectB-vpc'. The referenced network resource cannot be found.
In projectB, I do have a VPC called projectB-vpc.
What I do not understand is that in "projects/123456789000/global/networks/projectB-vpc", 123456789000 seems is for projectA as it is part of the email for projectA service account, while projectB-vpc is for projectB. In my command I have "projects/projectB/....", why the command replaced "projectB" with 123456789000?
Any idea where did I do wrong?
Thanks,
Philip
As per the GCP documentation you can create VM using a machine image from a different project directly. Please note that, when you create a VM by using a machine image from a different project, you might not have access to the service account attached to that source project. In my reproduction steps I followed this steps:
Created an Multi-regional Machine Image
2. gcloud beta compute machine-images add-iam-policy-binding rhel-machine-image \
--project=source-project \
--member='serviceAccount:Source-compute#developer.gserviceaccount.com' \
--role='roles/compute.admin'
Added the source project service account to destination project as iam.serviceAccountUser
4. gcloud beta compute instances create machine-image-vm --project=destination-project --zone us-central1-a --source-machine-image projects/source-project/global/machineImages/rhel-machine-image --service-account Destination-compute#developer.gserviceaccount.com
On the last step I used destination project Compute Engine Default Service Account.
Created [https://www.googleapis.com/compute/beta/projects/destination-project/zones/us-central1-a/instances/machine-image-vm].
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
machine-image-vm us-central1-a e2-medium x0.xxx.0.18 35.2x3.18x.x59 RUNNING
I believe if you keep the "default" network and subnet when you created the projects, GCP does that for you(I also believe most people will keep the default around),then the commands from the Google doc will work. But in my case, I deleted those defaults and created my own network and subnet, so I have to use the extra parameters --network and --subnet in the gcloud command to make it work.
I have multiple configurations created via the gcloud init command. It does not give me the option to set a Default Compute Region or a Default Compute Zone.
When I run, gcloud config configurations list, the default zone and region are empty.
gcloud config configurations ... only provides following commands. (No Update command)
activate
create
delete
describe
list
Can't I set a default region and zone when initializing a configuration? If no, how can I update certain fields of a gcloud configuration? Eg: COMPUTE_DEFAULT_ZONE or COMPUTE_DEFAULT_REGION
There is an associated gcloud command called gcloud config set that is used to set/update properties in the currently active configuration. What this means is that you can create a configuration, activate it and then perform gcloud config set commands to change the settings. Looking at the docs, both compute region and compute zone are documented as being present to set the default region and default zone respectively.
Just like Kolban mentioned if you look at the set configs you will find:
gcloud config set compute/zone [YOUR ZONE NAME HERE]
EXAMPLE: (gcloud config set compute/zone asia-east1-b)
Additionally, I like to also set the region as well at the same time
gcloud config set compute/region [YOUR REGION NAME HERE]
EXAMPLE: (gcloud config set compute/region asia-east1)
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