How to create a VM in GCP
-
Login to your gcp account. Select compute engine and then VM instance
-
create instance-> name (avoid capital latters) -> labels -> region (select your preferred region ) -> zone ( select one zone out of the options available) machine family -> General purpose ->E2, N2, N1, N2D, T2D -> Compute optimized -> Memory optimized -> GPU machine type -> Custom -> Shared core -> Standard -> High memory, high CPU boot disk -> public images -> custom images -> snapshots -> existing disk
Virtual machine is not compute engine. Compute engine has multiple services.
Compute Engine -> Virtual machine -> Virtual instance -> create instance
Few things to consider while creating VM instances: -Use small letters, numbers and avoid special characters. Do not assign ip address as its name to avoid security breach
- use labels as it acts as a tag and makes vm easily searchable
- Region and zone once selected, can not be changed for the VM instance
Manage VM instance using cloudshell
-
Login to gcp console -> select your project-> Activate cloud shell
Every command in cloudshell starts with gcloud
gcloud compute instances create myvm01 --machine-type n1-standard-1 --provisioning-model spot --zone us-central1-f
´´´
2. Now we access the newly created vm instance via ssh
```bash
gcloud compute ssh myvm01 --zone=us-central1-f
By default, debian is installed in the VM. Type ‘exit’ to come back to cludshell prompt
We can create a vm instance using image family as well.
gcloud compute images list
Say, we pick a centos image “Name-centos-stream-9-v20240709” with project as “centos-cloud” and family as “centos-stream-9” command looks like this:
gcloud compute instances create myvm02
--image-family centos-stream-9
--image-project centos-cloud
--zone us-central1-f
--machine-type n1-standard-1
- To stop this vm, the command will be:
gcloud compute instances stop vm02 - To start this VM. command will be:
gcloud compute instances start vm02 - To delete this vm, command will be:
gcloud compute instances delete vm02