How to create an SSD persistent disk boot disk in gcloud - google-cloud-platform

How can I create a boot disk type of SSD persistent disk using gcloud?
From the console I can create a VM instance with SSD persistent disk from the image. I am not able to do it using gcloud.
gcloud compute instances create instance1 --image img_name1 --image-project project_id --machine-type=type_value1 --zone=${CONFIG_zone}
By defaults it is creating a Standard Persistent Disk.

You are right, the default disk type for boot disks in new compute engine instances is "Standard persistent disk"
Try to use the optional parameter "--boot-disk-type" for the "gcloud compute instances create" command as described in the gcloud documentation.
With the following command I created a debian test instance with ssd boot disk:
gcloud compute instances create test-vm --machine-type=f1-micro \
--zone=europe-west4-b --boot-disk-type=pd-ssd
You can get the available disk types for each zone via the following gcloud command:
gcloud compute disk-types list
The disk typ "pd-ssd" however seems to be available in all zones.

Related

Copying VM between projects in GCP

I'm currently using windows VM instance in GCP(project1), i want to create same VM with data in my another project(project2)(project in another gmail account). The project2 have access to my project1 which i had setup IAM role.
So what the next step to copy the instance between the project1 to project2 (without loosing the data)?
You can copy a VM instance from one project to another either using a custom image or using disk.
Method 1: Using Custom image
You have to use the following steps to create a mirror VM in another project:
In your source project, create a snapshot of the VM's boot disk, using one of the below command:
$ gcloud compute snapshots create <SNAPSHOT_NAME> --source-disk <SOURCE_DISK> --source-disk-zone <SOURCE_DISK_ZONE>
Create a custom image from the snapshot using the following command:
$ gcloud compute images create <IMAGE_NAME> --source-snapshot=<SOURCE_SNAPSHOT> [--storage-location=<LOCATION>]
In your destination project, create a VM from the custom image using the following command:
$ gcloud compute instances create <VM_NAME> --image-project <IMAGE_PROJECT> [--image <IMAGE> | --image-family <IMAGE_FAMILY>]
Method 2: Using disk
In your source project, create a snapshot of the VM's boot disk, using one of the below command:
$ gcloud compute snapshots create <SNAPSHOT_NAME> --source-disk <SOURCE_DISK> --source-disk-zone <SOURCE_DISK_ZONE>
Then create a disk in the destination project with --source-snapshot:
$ gcloud compute disks create <DISK_NAME> --source-snapshot <SOURCE_SNAPSHOT> --project <destination-project>
Create a VM based on the new disk from step 2
$ gcloud compute instances create <VM_NAME> --project <destination-project> --disk name=<DISK_NAME>,boot=yes
Refer Copying VMs between projects for information.

How to browse the data on google's filestore server?

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.

Creating VM snapshot in GCP is not snapshotting the home folder

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

gcloud compute scp can't find filestore instance

Trying to copy some data into a newly created GCP Filestore with the gcloud CLI.
gcloud compute scp --recurse /somedirectore/somefile somefilestore-1:/somemount
gcloud seems unable to find the instance:
ERROR: (gcloud.compute.scp) Could not fetch resource:
- The resource 'projects/k8-spark/zones/us-central1-a/instances/somefilestore-1' was not found
The filestore instance does exist. Wondering if compute scp actually works with filestores? The documentation seems to think so:
https://cloud.google.com/filestore/docs/copying-data
Any help much appreciated!
The error indicates that "somefilestore-1" is not a name for a Compute Engine (GCE) instance, not a Filestore instance. You can find the instance name in Compute Engine [1]. If your instances were created by the Kubernetes Engine, it will likely start with "gke-< your_K8_cluster_name >".
Some section of the documentation refers to GCE instances as "VM instance", note that the Cloud Filestore fileshare is mounted on a Compute Engine Windows VM instance.
[1] https://console.cloud.google.com/compute/instances

How to change Region / Zone in Google Cloud?

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