Google Cloud

How to Create a virtual machine using the GCP command line

hello friends today i am gone to teach you how you can Create a virtual machine using the GCP command line.


Also visit:  How to Create Windows VM instance in google cloud


 

How to Create a virtual machine using the GCP command line

Some Basic Steps
  • Login to Your GCP Account Click here
  • To open GCP console, 
  • On Navbar, click on Icon to Open Cloud Shell button.
  • Ones its open it can ask for permission
  • Click Continue…

 

First we need to Know Zones and Region is default setup right now.

  • To display a list of all the zones in the region to which Qwiklabs assigned you, enter this partial command gcloud compute zones list | grep followed by the region that Qwiklabs or your instructor assigned you to.

 

Your completed command will look like this:

  • gcloud compute zones list | grep us-central1
 

To set your default zone to the one you just chose, enter this partial command gcloud config set compute/zone followed by the zone you chose.

Your completed command will look like this:

  • gcloud config set compute/zone us-central1-b
 
 
To create a VM instance called my-vm-2 in that zone, execute this command:

Your completed command will look like this:

gcloud compute instances create “my-vm-2” 
–machine-type “n1-standard-1” 
–image-project “debian-cloud”
–image “debian-9-stretch-v20190213” 
–subnet “default”

Note: The VM can take about two minutes to launch and be fully available for use.

Create VM instance with Your name

Some Basic Steps

  • Login to Your GCP Account Click here
  • To open GCP console, 
  • On Navbar, click on Icon to Open Cloud Shell button.
  • Ones its open it can ask for permission 
  • Click Continue…
 

To display a list of all the zones in the region to Run This command.

Your completed command will look like this:

 

  • gcloud compute zones list | grep </span >enter you zone name

Choose a zone from that list.
After Choosing zone name.

 
Your completed command will look like this:
  • gcloud config set computeenter you zone name
 
 

To create a VM instance called ( sachin ) in that zone, execute this command

Your completed command will look like this:
 
gcloud compute instances create “sachin” 
–machine-type “n1-standard-1″ 
–image-project “debian-cloud” 
–image “debian-9-stretch-v20190213″ 
–subnet “default”
 
Note: The VM can take about two minutes to launch and be fully available for use.

Important Points…

In first Line 

  • gcloud compute instances create “Sachin”

In Second Line 

  • –machine-type “n1-standard-1”

In Third Line 

  • –image-project “debian-cloud”

In Fourth Line 

  • –image “debian-9-stretch-v20190213”

Hit Enter..

Now your VM Instance taking two minutes to ready…