Skip to main content

Command Palette

Search for a command to run...

Fundamental Task for Beginners using Compute Engine

Updated
9 min read

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

  1. Open your web browser and go to goole cloud console.

  2. Sign in with your Google account if you're not already logged in.

Step 2: Open the Compute Engine Page

  1. In the Google Cloud Console, click on the Navigation menu (three horizontal lines) on the top-left corner.

  2. Select Compute Engine > VM instances.

Step 3: Create a New VM Instance

  1. 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-micro machine 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

  1. After reviewing the settings, click Create at the bottom of the page.

  2. 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

  1. Open your browser and go to Google Cloud Console.

  2. Log in with your Google account if you haven't already.

Step 2: Open the Compute Engine Page

  1. Click on the Navigation Menu (three horizontal lines on the top-left corner).

  2. Select Compute Engine > VM instances.

Step 3: Create a New VM Instance

  1. On the VM instances page, click Create instance.

  2. You'll be taken to the instance creation page where you can configure the settings.

Step 4: Configure VM Settings

  1. Name: Give your VM instance a name (e.g., vm-with-extra-disk).

  2. Region and Zone: Choose a region and zone (or leave the default).

  3. Machine Configuration:

    • Series: Keep the default (e.g., E2).

    • Machine type: Choose the machine type (e.g., e2-micro for a small instance).

Step 5: Configure the Boot Disk

  1. Scroll down to the Boot disk section.

  2. 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

  1. Scroll down to the Additional storage and VM backups section.

  2. 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).

  3. Click Done when finished configuring the disk.

Step 8: Create the VM Instance

  1. Review the settings.

  2. 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

  1. Open your browser and go to Google Cloud Console.

  2. Log in with your Google account if you haven't already.

Step 2: Open the Compute Engine Page

  1. Click on the Navigation Menu (three horizontal lines on the top-left corner).

  2. Select Compute Engine > VM instances.

Step 3: Create a New VM Instance

  1. On the VM instances page, click Create instance.

  2. You'll be taken to the instance creation page where you can configure the settings.

Step 4: Configure the VM Settings

  1. Name: Give your VM a name (e.g., predefined-image).

  2. 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

  1. Scroll to the Boot disk section.

  2. Click Change under the Boot disk section to select a predefined image.

  3. 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)

  4. Select the Version of the OS (e.g., Ubuntu 22.04, Windows Server 2019).

  5. 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).

  6. 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.

  1. 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.

  1. 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

  1. Review all the settings and click Create.

  2. 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

  1. Open your browser and go to Google Cloud Console.

  2. Sign in with your Google account if you're not already logged in.

Step 2: Open the Compute Engine Page

  1. Click the Navigation Menu (three horizontal lines on the top-left corner).

  2. Select Compute Engine > VM instances.

Step 3: Create a New VM Instance

  1. On the VM instances page, click Create instance.

  2. You’ll be taken to the instance creation page.

Step 4: Configure Basic VM Settings

  1. Name: Give your VM a name (e.g., snapshot-1).

  2. 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

  1. Scroll down to the Boot disk section.

  2. Click Change under the Boot disk section.

  3. 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).

  4. Click Select after configuring the boot disk with the snapshot.

Step 6: Configure Machine Type

  1. 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)

  1. Scroll down to the Firewall section.

  2. 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

  1. Review all the settings.

  2. 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

  1. Open your browser and go to Google Cloud Console.

  2. Sign in with your Google account.

Step 2: Open the Compute Engine Page

  1. Click the Navigation Menu (three horizontal lines on the top-left corner).

  2. Select Compute Engine > VM instances.

Step 3: Create a New VM Instance

  1. On the VM instances page, click Create instance.

  2. You’ll be directed to the instance creation page.

Step 4: Configure Basic VM Settings

  1. Name: Give your VM a name (e.g., startup-script).

  2. Region and Zone: Choose the region and zone where you want the VM to run (or leave it as default).

  3. Machine Configuration: Choose the machine type (e.g., e2-mic``ro for a small instance).

Step 5: Configure Boot Disk

  1. Scroll down to the Boot disk section.

  2. 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

  1. Scroll down to the security, disks, networking, sole tenancy section.

  2. Click the Advanced tab to expand it.

  3. In the Automation section, you’ll see a field labeled Startup script.

  4. 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.

  1. 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

  1. Review all settings and make sure everything is correct.

  2. Click Create to start provisioning the VM.

Task 8: Host a Simple Website on a VM

Step 1: SSH into the VM

  1. Go to the Google Cloud Console.

  2. Navigate to Compute Engine > VM instances.

  3. 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.

  1. Copy the External IP address of your VM.

  2. 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!

More from this blog

md_danish

6 posts