Creating A VM in Google Cloud
Creating A VM in Google Cloud
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a
persistent 5GB home directory and runs on the Google Cloud. Google Cloud Shell
provides command-line access to your GCP resources.
1. In GCP console, on the top right toolbar, click the Open Cloud Shell button
You can click "START CLOUD SHELL" immediately when the dialog box opens.
It takes a few moments to provision and connect to the environment. When you are
connected, you are already authenticated, and the project is set to your PROJECT_ID. For
example:
gcloud is the command-line tool for Google Cloud Platform. It comes pre-installed on
Cloud Shell and supports tab-completion.
You can list the active account name with this command:
Credentialed accounts:
- <myaccount>@<mydomain>.com (active)
Example output:
Credentialed accounts:
- [email protected]
You can list the project ID with this command:
[core]
project = <project_ID>
Example output:
[core]
project = qwiklabs-gcp-44776a13dea667a6
Full documentation of gcloud is available on Google Cloud gcloud Overview.
Learn more about regions and zones and see a complete list in Regions & Zones documentation.
In the GCP Console, on the top left of the screen, select Navigation menu > Compute
Engine > VM Instances:
us-central1 (Iowa)
or Learn more about regions in Regions &
Region
Zones documentation.
asia-south1 (Mumbai)
us-central1-c
or
Learn more about zones in Regions & Zones
Zone
asia-south1-c documentation.
Note: remember the zone that you
selected, you'll need it later.
2 vCPUs
This is a (n1-standard-2),
2-CPU, 7.5GB RAM instance. Note: A new project has a default resource
Machine quota, which may limit the number of CPU
Type cores. You can request more when you work
There are a number of machine
on projects outside of this lab.
types, ranging from micro instance
types to 32-core/208GB RAM
instance types. Learn more in
the Machine Types documentation.
Click Create.
Wait for it to finish - it shouldn't take more than a minute.
Once finished, you should see the new virtual machine in the VM Instances page.
To SSH into the virtual machine, click on SSH on the right hand side. This launches a SSH
client directly from your browser.
Note: For more information, see the Connect to an instance using ssh documentation.
Install a NGINX web server
Now you'll install NGINX web server, one of the most popular web servers in the world, to
connect your virtual machine to something.
root 2330 0.0 0.0 159532 1628 ? Ss 14:06 0:00 nginx: master process
/usr/sbin/nginx -g daemon on; master_process on;
www-data 2331 0.0 0.0 159864 3204 ? S 14:06 0:00 nginx: worker process
www-data 2332 0.0 0.0 159864 3204 ? S 14:06 0:00 nginx: worker process
root 2342 0.0 0.0 12780 988 pts/0 S+ 14:07 0:00 grep nginx
Awesome! To see the web page, go to the Cloud Console and click the External IP link
of the virtual machine instance. You can also see the web page by adding the External
IP to http://EXTERNAL_IP/ in a new browser window or tab.
You should see this default web page:
To check your progress in this lab, click Check my progress below. A checkmark means
you're on track.
Create a Compute Engine instance and add Nginx Server to your instance with necessary firewall rules.
Check my progress
Created [...gcelab2].
NAME ZONE MACHINE_TYPE ... STATUS
gcelab2 us-central1-c n1-standard-2 ... RUNNING
Click Check my progress below to verify you're on track in this lab.
Create a new instance with gcloud.
Check my progress
The instance created has these default values:
Finally, you can SSH into your instance using gcloud as well. Make sure you add your
zone, or omit the --zone flag if you've set the option globally:
gcloud compute ssh gcelab2 --zone [YOUR_ZONE]
(Output)
WARNING: The public SSH key file for gcloud does not exist.
WARNING: The private SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: [/usr/bin/ssh-keygen] will be executed to generate a key.
This tool needs to create the directory
[/home/gcpstaging306_student/.ssh] before being able to generate SSH
Keys.
Now you'll type Y to continue.
Do you want to continue? (Y/n)
Enter through the passphrase section to leave the passphrase empty.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase)
After connecting, you disconnect from SSH by exiting from the remote shell:
exit
Congratulations!
Google Compute Engine is the foundation to GCP's Infrastructure-as-a-Service. You
created a virtual machine with Compute Engine and can now map your existing server
infrastructure, load balancers, and network topology to GCP.