Learn How to Develop Apps on Google Cloud Easily
Aims to create a VM and install + run nginx server on G-cloud
3rd step from a series that focuses on understanding G-cloud.
*******************************************************************************
Google Cloud offers a variety of compute services spanning different usage options.
For general workloads that require dedicated resources for your applications, Compute Engine is a good option.
If you’re looking for a platform as a service, App Engine is a good option.
Cloud Functions offers a serverless option for triggering code to run based on some kind of event.
To run containers on a managed Kubernetes platform, you can leverage GKE.
And Cloud Run is a fully managed serverless platform that lets you develop and deploy highly scalable containerized applications.
Compute Engine
Hands on google cloud
Create a VM with the Cloud console.
Create a VM with the gcloud command line.
Deploy a web server and connect it to a VM.
Prerequisites
- Familiarity with standard Linux text editors such as vim, emacs, or nano.
Create a VM with the Cloud console.
In this section, you create new predefined machine types with Compute Engine from the Cloud console.
- In the Cloud console, on the Navigation menu (), click Compute Engine > VM Instances.
This may take a minute to initialize for the first time.
- To create a new instance, click CREATE INSTANCE.
- There are many parameters you can configure when creating a new instance. Use the following for this lab:
Field | Value | Additional Information |
Name | gcelab | Name for the VM instance |
Region | <REGION> | For more information about regions, see the Compute Engine guide, Regions and Zones. |
Zone | <ZONE> | Note: Remember the zone that you selected to use later. For more information about zones, see the Compute Engine guide, Regions and Zones. |
Series | E2 | Name of the series |
Machine Type | 2 vCPU | This is an (e2-medium), 2-CPU, 4GB RAM instance. Several machine types are available, ranging from micro instance types to 32-core/208GB RAM instance types. For more information, see the Compute Engine guide, About machine families. Note: A new project has a default resource quota, which may limit the number of CPU cores. You can request more when you work on projects outside this lab. |
Boot Disk | New 10 GB balanced persistent disk OS Image: Debian GNU/Linux 11 (bullseye) | Several images are available, including Debian, Ubuntu, CoreOS, and premium images such as Red Hat Enterprise Linux and Windows Server. For more information, see Operating System documentation. |
Firewall | Allow HTTP traffic | Select this option in order to access a web server that you install later. Note: This automatically creates a firewall rule to allow HTTP traffic on port 80. |
![A screenshot of a computer
Description automatically generated](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdifHJW7I9E_5cDvkWZhi5WczrxB9f2w-a0uRqTTmZ3kZA7dhEoy-cjhj1PZjfMYp2Wyadk0avmEydmE6AryyxnCAdh59JAR4msEuyLLiHCDVkzWpBJ94ncacaqLd78yMgtjyChujXcrVocMGDlRsQ9kaxUR38iju6wRKqqsPUmomTwgc8kQ?key=h8e2-XDxbp_MLGj2QmA0g align="left")
- Click Create.
It should take about a minute for the VM, gcelab, to be created. After gcelab is created, the VM Instances page lists it in the VM instances list.
- To use SSH to connect to the VM, click SSH to the right of the instance name, gcelab.
This launches an SSH client directly from your browser.
Note: Learn more about how to use SSH to connect to an instance from the Compute Engine guide, Connect to Linux VMs using Google tools.
Install an NGINX web server
Now to install an NGINX web server, one of the most popular web servers in the world, to connect your VM to something.
- Update the OS:
sudo apt-get update
Expected output:
- Install NGINX:
sudo apt-get install -y nginx
- Confirm that NGINX is running:
ps auwx | grep nginx
- To see the web page, return to the Cloud console and click the External IP link in the row for your machine, or add the External IP value to http://EXTERNAL_IP/ in a new browser window or tab.
![A screenshot of a computer
Description automatically generated](https://lh7-rt.googleusercontent.com/docsz/AD_4nXcOnUVNIrpc3Usv5bD826vhs-TSfTTV3Jn2qQu0Bv_mt-LCd3NCJfMPS5Jw3aLg33K5EMoYE375cQExMpMhhn3onmAFuBP-NVE7LID74SRSJN9AZwMbUw-z2McHtB9XHFEK5s_uY9g9guoWginq8IWwPSbW6ucMuwvNXyPmZU5vPXiqZDGk?key=h8e2-XDxbp_MLGj2QmA0g align="left")
This default web page should open. For me- it launched same
Create a new instance with gcloud
Note: To view a menu with a list of Google Cloud products and services, click the Navigation menu at topleft
Instead of using the Cloud console to create a VM instance, use the command line tool gcloud, which is pre-installed in Google Cloud Shell. Cloud Shell is an interactive shell environment for Google Cloud loaded with all the development tools you need (gcloud, git, and others) and offers a persistent 5-GB home directory.
Set the region and zone
- Set the project region for this lab:
gcloud config set compute/region europe-west4
- Create a variable for region:
export REGION=europe-west4
- Create a variable for zone:
export ZONE=europe-west4-a
Learn more from the Regions & Zones documentation.
Note: When you run gcloud on your own machine, the config settings are persisted across sessions. But in Cloud Shell, you need to set this for every new session or reconnection.
Note: If you want to try this on your own machine, read the gcloud command line tool guide.
- In the Cloud Shell, use gcloud to create a new VM instance from the command line:
gcloud compute instances create gcelab2 --machine-type e2-medium --zone=$ZONE
Expected output:
![A black screen with white text
Description automatically generated](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeNM_b_4kVAHMzxQDX6r3lET4twWx6sW4vD0PTLrILQz7hudvo5Hs4Yi05ArmNwPXA_OfzGj6RMPh1o1Bi5labE9Js4xHtj1FN83UrACjtOvpqguTiF0yyEApCqFbRp7xEmzmECcUnmZwdbSmYhuwAmKWjfr3dKzdCl4aAwrUiN-ZnsF4vTA?key=h8e2-XDxbp_MLGj2QmA0g align="left")
The new instance has these default values:
The latest Debian 11 (bullseye) image.
The e2-medium machine type.
A root persistent disk with the same name as the instance; the disk is automatically attached to the instance.
When working in your own project, you can specify a custom machine type.
To see all the defaults, run:
gcloud compute instances create –help
Note: You can set the default region and zones that gcloud uses if you are always working within one region/zone and you don't want to append the --zone flag every time.
To do this, run these commands:
gcloud config set compute/zone ...
gcloud config set compute/region ...
To exit help, press CTRL + C.
![A screen shot of a computer
Description automatically generated](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdiH9RY4Nc6hzQB11WAbgww-UIcEuJXaOmVUG_GAtxwpER4oQw1RXGpW4KcTyX31Ys4L1qrp2zsonPb1VkEQK2FWDCyGjmRarYxcxpmeNxjYfyfVIs-iNzaIzJ_JszvbVk3fMSztjnyyF2YAdVHCJCycH3oEik7HwpAdctvsPpxl3mJlwQSFM?key=h8e2-XDxbp_MLGj2QmA0g align="left")
In the Cloud console, on the Navigation menu, click Compute Engine > VM instances.
Your two new instances should be listed.![A screenshot of a computer
Description automatically generated](https://lh7-rt.googleusercontent.com/docsz/AD_4nXePXl52nxuC7PUMFOrCrX2x2nRd920-QJQIevyNfHiSEOldJuXCEXMUM_D6VRLfCfzFgPUCW9iGzhjxhWJ2JwgA_iE0iTIgZiMQScC78u2e8o3CakHV5HkMsu5Hc6un7Hkopi-zwJThslBxqnBpu8GxAtOabCI84N7F-j0oMEvjYziw3ECAjw?key=h8e2-XDxbp_MLGj2QmA0g align="left")
- You can also use SSH to connect to your instance via gcloud. Make sure to add your zone, or omit the --zone flag if you've set the option globally:
gcloud compute ssh gcelab2 --zone=$ZONE
![A screenshot of a cell phone
Description automatically generated](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfh_jWcTeuU1BnrOgeqLU7dozZTQnkgRzePZKf4Wt1xs3gRhKZMHd8q3c7brQEMjRHgwhxqbjl3HRYKWSZ75s4BQbzKUI1SjdsKZ-CzPpmqM2r9-8l5onVJf6Sy-ucRjAwVDBcWjmcLV5PA821xBMyagtOqSjGoFYgZrlMR3p2OV7v4aE6oUQ?key=h8e2-XDxbp_MLGj2QmA0g align="left")
- Type Y to continue.
Do you want to continue? (Y/n)
Press ENTER through the passphrase section to leave the passphrase empty.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase)
After connecting, disconnect from SSH by exiting from the remote shell
Exit
That is it for now. Will continue further topics on Configure elastic apps and handson Containerization + orchestration on Google cloud.
Subscribe to my newsletter
Read articles from Nitin directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Nitin
Nitin
A Seasoned gate keeper for software quality (Manual / Automation (Web + Mobile native + API) / Performance test) with 13 years of experience, An automation🤖 lover and a continuous📚 learner. A test automation geek and a DevOps engineer using and exploring cloud☁️. Looking for opportunities in Cloud DevOps for mutual growth. (Working remotely since last 5 years with teams in Europe / USA and Canada)