Last updated on July 6th, 2023
Estimated reading time: 5 minutes
Google compute engine services allows users to create and run virtual machines on Google cloud infrastructure using (IAAS).
If you are new to Google cloud platform refer our article on Google cloud free tier account – Full Stack Tutorials Hub .
Create and Configure Virtual Machine using cloud console
First step to set up VM in google cloud is to enable compute engine API. Search for Google compute Engine in Search bar. This would display an option to enable Google Compute Engine API. If you are using compute engine resources for the first time this API needs to be enabled . Click on Enable and wait for some time to get it ready.
Click on Create instance. This will open up new window to configure virtual machine.
Name: Name of virtual machine
Labels: Labels are useful to easily identify and manage VM lists.
Regions and Zones: Select the Region and Zone where the VM needs to be deployed. Regions and Zones and cannot be changed later.
Choosing the right virtual machine type
General-purpose machines offering a good balance of price and performance and are suitable for a wide variety of common workloads including databases, development and testing environments, web applications, and mobile gaming.
Memory optimized machines offer the highest memory configurations. They are well suited to memory-intensive workloads such as large in-memory databases like SAP HANA, and in-memory data analytics workloads.
GPU based VM machines are designed for most demanding workloads such as machine learning.
Choosing the right machine family
General Purpose: Hosting general mills web applications select General purpose machine family.
Compute-optimized: Compute intensive workloads like gaming applications can be deployed on this workload.
Memory-Optimized: Memory-intensive workloads like gaming applications can be deployed on this workload.
Select OS Image
Click on Boot disk to select OS Image. Public Images are managed by Google and third party. Select Operating system and version.
Select boot disk type and Size.
To enable communication outside of Virtual machine, configure firewall rules. Allow Http and Https traffic.
Once all the configuration is done check VM monthly and hourly estimated costs are displayed.
To add additional disk, click on advance tab and specify disk type and size.
Configure start up scripts under automation tab.startup script that will run when your instance boots up or restarts. Startup scripts can be used to install software and updates, and to ensure that services are running within the virtual machine
Choose Availability policies
Availability policies: Spot VMs are available at lower price. Compute Engine might preempt Spot VMs if it needs to reclaim those resources for other tasks. At this uncertain preemption time, Compute Engine either stops (default) or deletes your Spot VMs depending on your specified termination action for each Spot VM. If your workloads are fault-tolerant and can withstand possible VM preemption, Spot VMs can reduce your Compute Engine costs significantly. Select Standard/Spot depending on your workload.
On host maintenance: When Compute Engine performs periodic infrastructure maintenance it can migrate your VM instances to other hardware without downtime. Select Migrate/Terminate depending on your workload.
Automatic restart: Compute Engine can automatically restart VM instances if they are terminated for non-user-initiated reasons (maintenance event, hardware failure, software failure and so on) . Select On/Off depending on your workload.
Install Apache server On Cloud Virtual Machine
External IP Address is used to communicate with resources on this VM from external world. This is the dynamic IP address and it would change when VM is stopped and restarted.
Click on SSH and it to log into VM.
To get root access execute query as below.
sudo su
Pull the latest changes using Debian package manager.
apt update
Install apache server
apt install apache2
This will install Apache server on our VM.
Click on External IP Adress and it would redirect you to Apache Home page.
Apache web server is up and running.
To learn more about advance virtual machine configuration in google cloud refer Set Up GCP Free VM In 10 Minutes – Google Cloud Tutorials.