This hands-on guide walks you through the process, from creating a Google Cloud Virtual Machine to advanced configurations and managing static IP addresses. Whether you’re deploying applications, learning about cloud services, or exploring GCP’s Compute Engine features like auto-scaling, load balancing, and machine type configurations, this tutorial has you covered. Learn how to leverage Google’s free credits, choose the right machine family and type, and ensure your VM is optimized for your needs. Plus, get insights into GCP’s pricing, free tier limits, and how to secure a static IP address for your projects.
This will be hands on tutorial, and you can follow along. Google cloud offers free credits worth 400 $ with free tier account. Learn more about gcp free tier account here Google Cloud Free Credits – Google Cloud Tutorials.
This will allow you to create your virtual machine and run your website in google cloud for free.
Google Compute Engine
Whenever you need to deploy your application in cloud you need virtual servers. Google compute engine allows you to set up and manage virtual machines in google cloud.
Features of Google Compute Engine
- Auto Scaling and load balancing
- Create and manage virtual machines in Google Cloud
- Attach storage to virtual machine
- Manage network connectivity for VM
Create a Google Cloud Virtual Machine
log into gcp console using your free trial account https://console.cloud.google.com/ .
click on create new project.
Enter project name and click on create project.
It is recommended practice to create new project to learn and explore google compute engine services. Running virtual servers in cloud would incur cost and amount will be debited from free credits. Once your work is done delete this project and it will delete all the cloud services in that project.
Search for “compute engine” in gcp console search bar.
Enable Compute Engine API
It will take around 2-3 minutes for the initial set up.
Click on create instance and enter a valid name for your virtual machines.
Google cloud supports configuration of labels for Virtual machines. Additional information for a virtual machine is added in labels. You can add 1 or more labels as per requirement.
Specify Region and Zone for your VM. It is recommended to use regions and zones nearest to your users.
Cloud VM Machine Family and Machine Type Configuration
Machine configuration decides the hardware for your virtual machine.
Google cloud offers 4 types of machine family.
- General Purpose: Machine types for common workloads optimized for cost and flexibility. This is suitable for hosting web applications, databases.
- Compute Optimized: Machine type optimized for compute intensive workloads. This is suitable for gaming applications which requires high compute power.
- Memory Optimized: Machine type optimized for memory intensive workloads. This is suitable for in memory data analytics type of workloads.
- GPU: Google cloud also supports additional of dedicated graphics processing unit to virtual machines. A common use case scenario would be machine learning and heavy data processing.
Depending on your workload appropriate machine family. The choice of machine family directly impacts the price of running virtual machines in google cloud.
Approximate price is computed at the moment of machine family configuration.
Once you have finalized machine family next step is to choose machine type to choose exact number of CPU’s, memory and disk.
For each of machine family there are multiple machine types.
Machine Type | VCPU’s | Memory | Bandwidth |
e2-standard-2 | 2 | 8 | 4 |
e2-standard-4 | 4 | 16 | 8 |
e2-standard-8 | 8 | 32 | 16 |
e2-standard-16 | 16 | 64 | 16 |
e2-standard-32 | 32 | 128 | 16 |
e2-standard-4 – e2- Machine type family
standard – Type of workload
4 – number of VCPU
Memory, networking increases with increase in number of VCPU’s.
Detailed pricing for machine family and machine types refer Pricing | Compute Engine: Virtual Machines (VMs) | Google Cloud.
Cloud VM OS Image configuration
Once machine type and machine family are configured next important step is to configure is the operating system and software you need to install on your VM instance.
Google cloud offers 2 different types of Images.
Public Images: Provided and maintained by google and open-source communities.
Custom Image: Created by you for your project.
Under boot disk tab click on click on change button.
It will display list of all available public images and custom images you have created.
Select boot disk to attach storage disk to your virtual machine.
Select storage size as per requirment.
Google cloud by default encrypts data on server side using google managed encryption keys. Under advance configuration you can specify type of data encryption.
Learn more about data encryption options in google cloud Google Cloud Storage Encryption – Cloud KMS – Google Cloud Tutorials.
For this tutorial this VM instance would be configured as application hosting server, and it would be used for http https communication.
Allow http https, traffic in firewall rules.
Google Cloud Virtual Machine Advance Configuration
You can configure VM as confidential VM under advance settings.
confidential VM ensures that your data and applications remain private when in use.
confidential VM can be configured at the time of VM creation.
SPOT VM
Google cloud offers spot virtual machines for fault tolerant workloads. Spot virtual machines are available at much discounted rates compared to standard VM machines but has lower availability.
If your workload is batch processing jobs Spot VM are best suited for this. Google cloud compute engine can preempt spot VM at any point of time.
Spot VM cannot be live migrated to standard VM, and it comes with limited number of compute resources and lower availability.
To configure Virtual Machine as Spot VM under availability policies select Spot.
Live Host migration
Google cloud also supports live migration of VM to different host during maintenance to ensure zero downtime.
To enable live migration in advance settings under host maintenance select ‘migrate vm instance ‘
Select VM restart ON in case VM is terminated by non-user reasons like hardware failures, software failures.
Sole-tenancy
Google compute engine supports sole tenancy configuration for specific machine family and types of virtual machines.
sole tenancy allows you to group your VM under common dedicated host physically separated from other virtual machines. The underlying resources and host hardware is dedicated in case of sole tenant nodes.
sole tenancy can be configured under advance tab.
Gaming applications,machine learning is best fitted for sole tenancy use case.
Review Virtual Machine configuration and click on create.
It will take 2-4 minutes for virtual machine to set up in google cloud environment.
Internal and External IP Address of Google Cloud Virtual Machine
When the virtual machine set up is complete it will have External and Internal IP address associated with It.
Whenever a new VM instance is created it will have at least one internal IP address attached to it. Internal IP address is specific to a corporate network and used for internal communication with google cloud. Internal Ip address is static and remains attached to virtual machine even if it is stopped.
Virtual machine may or may not have an external IP address and it depends on how the machine is been configured. External IP address is used by external services and resources to communicate with Virtual Machine.
External IP address is dynamic and changes each time VM restarts.
VM instances tab will list all the available virtual machines.
To access and log into virtual machine click on SSH under connect.
Compute engine sets the username and create SSH key pair. Private and public SSH keys are stored in browser session and has expiry of 5 Minutes.
Google cloud platform uses key based SSH authentication to connect with Linux based virtual machines.
To become root user execute below command
sudo su
Pull latest changes using Debian package manager.
apt update
Install Apache server for http communication.
apt install apache2
Once Apache server installation is complete type external IP address in browser and it will display Apache homepage.
Stop virtual machine using stop button.
Once VM instance is stopped it will not have green status and there should not be any External IP address attached with VM.
VM instance will continue to have Internal IP address.
Restart VM instance using start button.
It will take 2-4 minutes for VM instance to get started.
Once Virtual machine is restarted it will again show green status and it will have an external IP address. External IP address is dynamic, and it can be different in this case.
Static IP address
In google gcp console search vpc networks.
Navigate to IP Address tab and it you display list of all IP addresses.
Click on Reserve External IP address.
To Reserver external IP address of Virtual machine as static IP address and Virtual Machine has to be in same region.
Enter name and description to reserve a static IP resource.
Select the region from dropdown and it will display list of available Virtual machines in this region.
Attach this IP address with a virtual machine.
Navigate to compute engine and you should see reserve IP address is mapped to external IP of virtual machine.
Right click and stop this virtual machine.
The VM instance will retain external IP address when it is stopped.
Now restart VM instance and you will see the same IP address.
Points to consider when working with static IP address.
- Static IP addresses can be assigned to any virtual machine in the same region.
- When VM instance is deleted static IP address is not deleted automatically and it needs to be removed explicitly.
- Static IP address will incur cost even when Virtual machine is not in use.
- The billing cost for static IP address when not in use is more than when it is been used.
Learn more about static IP address pricing here Reserve a static external IP address | Compute Engine Documentation | Google Cloud
Delete Virtual Machine and release all cloud resources.
Delete Static IP address.
Is VM free on GCP?
Google cloud platform offers 1 non preemptible virtual machine e2 instance configuration for free and usage is not debited from free credits.
VM instance must be created in one of the following regions.
Oregon: us-west1
owa: us-central1
South Carolina: us-east1
It supports 30 GB of standard persistent disk size.
1 GB network egress from North America to all region destinations.
What are the limits of GCP always free?
GCP free virtual machine is free based on usage of hours and not based on duration in days.
It offers virtual machine with e2 configuration for free usage hours per month.
How do I create a free virtual machine on Google Cloud?
If you are new user, you can opt in for gcp free trial account and entitle for free credits worth 300 $.
If you authenticate your corporate email Id, you can get additional 100 $.
This 400 $ worth credits can be used to host your applications on google compute engine till free credits are exhausted.
Another option to get GCP Free VM is to follow above steps and create a virtual machine with e2 configuration.
GCP offers free usage hours per month for virtual machines created in selected regions.
What is the cheapest GCP virtual machine?
Spot VMs are highly affordable virtual machines for fault tolerant workloads like batch job processing.