Fundamental Task for Beginners using Compute Engine
In this blog, we will explore different methos for creating VM instances:
Task 1: Create a Simple VM (Compute Engine Instance)
To create a simple Virtual Machine (VM) using default settings in Google Cloud Platform (GCP), you can follow these steps using the Google Cloud Console-
Step 1: Sign in to Google Cloud Console
Open your web browser and go to goole cloud console.
Sign in with your Google account if you're not already logged in.
Step 2: Open the Compute Engine Page
In the Google Cloud Console, click on the Navigation menu (three horizontal lines) on the top-left corner.
Select Compute Engine > VM instances.

Step 3: Create a New VM Instance
- On the VM instances page, click Create instance.
You'll be directed to the instance creation page with several options pre-filled for you.

Step 4: Configure the VM with Default Settings
Google Cloud fills most of the settings with default values, but here's a breakdown:
Name: Enter a name for your VM instance (e.g.,
new-instance).Region and Zone: By default, GCP selects the closest region and zone based on your location. You can leave this as is or choose a different one if needed.
Machine Configuration:
Series: Choose the default (e.g., E2).
Machine type: By default, GCP selects the
e2-micromachine type, which is cost-effective and sufficient for lightweight tasks.
Boot Disk:
Operating System: By default, GCP uses the latest Debian Linux image.
Size: The default boot disk size is typically 10 GB, which can be left unchanged.
Firewall:
- Check the boxes to allow HTTP and HTTPS traffic if you plan to run a web server on the VM.
Step 5: Create the VM Instance
After reviewing the settings, click Create at the bottom of the page.
GCP will start provisioning your VM, which might take a few second.


Task 2 : Create a VM with Attached Disk.
To create a VM with an additional persistent disk for storage in Google Cloud Platform (GCP), follow these steps-
Step 1: Sign in to Google Cloud Console
Open your browser and go to Google Cloud Console.
Log in with your Google account if you haven't already.
Step 2: Open the Compute Engine Page
Click on the Navigation Menu (three horizontal lines on the top-left corner).
Select Compute Engine > VM instances.
Step 3: Create a New VM Instance
On the VM instances page, click Create instance.
You'll be taken to the instance creation page where you can configure the settings.
Step 4: Configure VM Settings
Name: Give your VM instance a name (e.g.,
vm-with-extra-disk).Region and Zone: Choose a region and zone (or leave the default).
Machine Configuration:
Series: Keep the default (e.g., E2).
Machine type: Choose the machine type (e.g.,
e2-microfor a small instance).
Step 5: Configure the Boot Disk
Scroll down to the Boot disk section.
By default, GCP will select the latest Debian image, with a 10 GB disk. You can change the size or OS image here if required.
Step 6: Add an Additional Persistent Disk
Scroll down to the Additional storage and VM backups section.
Click Add new disk to create a new persistent disk.
Name: Enter a name for the additional disk (e.g.,
disk).Type: Choose between Standard Persistent Disk (HDD) or SSD Persistent Disk. SSD is faster, but HDD is cheaper.
Size: Specify the size of the disk (e.g., 50 GB).
Click Done when finished configuring the disk.

Step 8: Create the VM Instance
Review the settings.
Click Create at the bottom of the page. GCP will now create your VM instance with the additional persistent disk.

Task 3: Create a VM Using a Predefined Image
To create a Virtual Machine (VM) using a predefined image in Google Cloud Platform (GCP), follow these steps
Step 1: Sign in to Google Cloud Console
Open your browser and go to Google Cloud Console.
Log in with your Google account if you haven't already.
Step 2: Open the Compute Engine Page
Click on the Navigation Menu (three horizontal lines on the top-left corner).
Select Compute Engine > VM instances.
Step 3: Create a New VM Instance
On the VM instances page, click Create instance.
You'll be taken to the instance creation page where you can configure the settings.
Step 4: Configure the VM Settings
Name: Give your VM a name (e.g.,
predefined-image).Region and Zone: Choose a region and zone where you want your VM to be hosted (or leave it as the default).
Step 5: Select a Predefined Image
Scroll to the Boot disk section.
Click Change under the Boot disk section to select a predefined image.
In the Operating system dropdown, select the predefined image you want. You can choose from several popular OS images like:
Debian
Ubuntu
CentOS
Windows Server
Red Hat Enterprise Linux (RHEL)
SUSE Linux Enterprise Server (SLES)
Select the Version of the OS (e.g., Ubuntu 22.04, Windows Server 2019).
Optionally, adjust the Boot disk type (either Standard Persistent Disk or SSD Persistent Disk) and the Size of the boot disk (default is 10 GB).
Click Select after choosing the predefined image.

Step 6: Configure Machine Type
Under the Machine configuration section, choose the machine type. The default is e2-micro, which is suitable for lightweight tasks.
- You can adjust the Series and Machine type if you need more resources.
Step 7: Configure Networking and Firewall
Scroll down to the Firewall section.
- Check the boxes to allow HTTP and HTTPS traffic if you plan to run a web server on the VM.
Step 8: Review and Create the VM
Review all the settings and click Create.
The VM will take a few moments to be provisioned.

Task 4: Create a VM from a Snapshot
To create a Virtual Machine (VM) from a snapshot in Google Cloud Platform (GCP), you can follow these steps
Step 1: Sign in to Google Cloud Console
Open your browser and go to Google Cloud Console.
Sign in with your Google account if you're not already logged in.
Step 2: Open the Compute Engine Page
Click the Navigation Menu (three horizontal lines on the top-left corner).
Select Compute Engine > VM instances.
Step 3: Create a New VM Instance
On the VM instances page, click Create instance.
You’ll be taken to the instance creation page.
Step 4: Configure Basic VM Settings
Name: Give your VM a name (e.g.,
snapshot-1).Region and Zone: Choose the region and zone where you want your VM to be hosted (or leave it as the default).
Step 5: Configure Boot Disk from Snapshot
Scroll down to the Boot disk section.
Click Change under the Boot disk section.
In the Boot disk window, follow these steps:
Click on the Snapshots tab.
From the Snapshot dropdown, select the snapshot you want to use to create the VM.
Choose the Disk type (either Standard persistent disk or SSD persistent disk).
Optionally, adjust the Disk size (it should be at least the size of the snapshot, but you can increase it if you need more storage).
Click Select after configuring the boot disk with the snapshot.

Step 6: Configure Machine Type
- Under the Machine configuration section, select the machine type. The default is
e2-micro, but you can select a different type based on your workload.
Step 7: Configure Networking and Firewall (Optional)
Scroll down to the Firewall section.
Check the boxes to allow HTTP and HTTPS traffic if required (e.g., if you're running a web server).
Step 8: Create the VM Instance
Review all the settings.
Click Create to provision the VM from the snapshot.

Task 5: Create a VM with a Startup Script
Step 1: Sign in to Google Cloud Console
Open your browser and go to Google Cloud Console.
Sign in with your Google account.
Step 2: Open the Compute Engine Page
Click the Navigation Menu (three horizontal lines on the top-left corner).
Select Compute Engine > VM instances.
Step 3: Create a New VM Instance
On the VM instances page, click Create instance.
You’ll be directed to the instance creation page.
Step 4: Configure Basic VM Settings
Name: Give your VM a name (e.g.,
startup-script).Region and Zone: Choose the region and zone where you want the VM to run (or leave it as default).
Machine Configuration: Choose the machine type (e.g.,
e2-mic``rofor a small instance).
Step 5: Configure Boot Disk
Scroll down to the Boot disk section.
Leave the default OS, or click Change if you want to use a different predefined image (e.g., Debian, Ubuntu).
Step 6: Add a Startup Script
Scroll down to the security, disks, networking, sole tenancy section.
Click the Advanced tab to expand it.
In the Automation section, you’ll see a field labeled Startup script.
Enter your startup script here.

This script will:
Update the package list
Install the Apache web server
Start the Apache service
Enable the Apache service to run on boot
Create a simple "Hello, World" page for testing
Step 7: Configure Firewall
Scroll down to the Firewall section.
- Check the boxes to allow HTTP and HTTPS traffic, especially if your startup script involves web services (e.g., Apache).
Step 8: Review and Create the VM
Review all settings and make sure everything is correct.
Click Create to start provisioning the VM.


Task 8: Host a Simple Website on a VM
Step 1: SSH into the VM
Go to the Google Cloud Console.
Navigate to Compute Engine > VM instances.
Find your VM instance and click SSH to open a terminal session in the browser.
Step 2: Update and Install Apache Web Server
Once you are connected to the VM via SSH, follow these steps:
Update the package list
sudo apt update
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2

Step 3: Create a Simple HTML Website
cd /var/www/html/
sudo rm index.html
sudo nano index.html
Add simple HTML content
<!DOCTYPE html>
<html>
<head>
<title>My Simple Website</title>
</head>
<body>
<h1>Welcome to My Simple Website!</h1>
<p>This website is hosted on a Google Cloud VM using Apache!</p>
</body>
</html>


Step 4: Verify the Website
Go to Compute Engine > VM instances in the Google Cloud Console.
Copy the External IP address of your VM.
Open your browser and type the external IP into the address bar (e.g.,
http://<EXTERNAL_IP>).
You should now see the simple webpage you just created!

Conclusion
By following these tasks, one should now have a solid understanding of how to create, manage, and customize virtual machines in Google Cloud’s Compute Engine. Whether launching simple instances or more complex setups, Compute Engine provides the flexibility to adapt to various use cases. Continue experimenting to further build cloud skills!