Fundamental Task for Beginners using Compute Engine

Hridhi KumariHridhi Kumari
5 min read

Google Cloud's Compute Engine is a scalable, flexible, and powerful Infrastructure-as-a-Service (IaaS) offering that allows users to create and manage virtual machines (VMs) in the cloud. This blog will guide through some beginner-level tasks that cover the basics of using Compute Engine.

Task 1: Create a Simple VM (Compute Engine Instance)

The first step to getting started with Compute Engine is launching a basic Virtual Machine (VM). Here’s how to create one using default settings.

Steps:

  1. Navigate to the Google Cloud Console.

    https://console.cloud.google.com

  2. Go to Select Project, click New Project add project name, select organization( if student then go for no organization ) and then click Create.

  3. search Compute Engine API, click Enable.

  4. Navigate to Compute Engine.

  5. In the Compute Engine section, click VM Instance.

  6. Select Create Instance.

  7. Use the default Name, Location(region, zone), Machine type(E2, N2) and OS (Debian or Ubuntu) etc.

  8. Click Create to launch VM Instance.

VM Instance should now be up and running. This instance can be used to perform basic operations and explore Google Cloud features.

Task 2: Create a VM with an Attached Disk

Sometimes, the default storage provided with a VM may not be sufficient for the workload. An additional persistent disk can be created and attached to the existing VM for expanded storage.

Steps:

  1. Create a new VM Instance by following the steps in Task 1.

  2. Scroll to the Storage section and click Add new disk.

  3. Define the size, type, and encryption for the disk.

  4. Click SAVE to launch the VM with the attached disk.

This will create a VM instance with additional storage.

Note: The disk size can be increased whenever necessary; however, once the disk size is increased, it cannot be reduced.

Task 3: Create a VM Using a Predefined Image

Google Cloud offers a variety of predefined images (like Ubuntu, CentOS, Windows) that can be used to launch a VM quickly. Here’s how to launch a VM using one of these images.

Steps:

  1. In Compute Engine > VM Instances and click Create Instance.

  2. In the Boot Disk section, click Change.

  3. Browse through the list of predefined images and select one (e.g., Ubuntu 20.04 LTS).

  4. Click Select and then Create to proceed.

Task 4: Create a VM from a Snapshot

Snapshots allow to capture the state of a disk, which can later be used to restore or clone a VM. If a snapshot is available, a new VM can be easily launched using that snapshot.

Steps:

  1. Navigate to Compute Engine > Snapshots.

  2. Click Created Snapshot to take snapshot of VM Instance.

    We can also create VM Instance using an existing Snapshot.

  3. Go to previously created snapshot and click Create Instance.

  4. While creating a new VM, in the Boot Disk section, select Snapshot as the source.

  5. Select previous snapshot from the list and click Select and then click Create.

This is useful for restoring a system to a previous state or replicating VMs.

Task 5: Create a VM with a Startup Script

Startup scripts can be used to automate configuration tasks when a VM boots up. Example:- software can be automatically installed or settings updated.

Steps:

  1. Start by creating a VM Instance by using steps in Task1.

  2. In the Management, Security, Disks section, click Management.

  3. In the Startup script box, add a simple script, like installing Apache:

     #!/bin/bash 
     sudo apt-get update 
     sudo apt-get install apache2 -y
    
  4. Click Create to launch the VM Instance with the script.

This script will automatically run when the VM is first booted, installing Apache in the process.


Task 6: Accessing a VM via SSH

Once VM Instance is created, we can connect to it using SSH from the Google Cloud Console or a terminal.

Steps:

  1. In the Compute Engine > VM Instances.

  2. Find the instance you want to connect to and click SSH.

  3. Click Authorize to connect SSH with your VM Instance.

  4. A browser-based SSH terminal will open, allowing us to interact with our VM Instance.

Task 7: Install Software on a VM

Software packages like Nginx and Apache can be installed by using SSH into the VM and package managers.

Steps :

  1. Connect to your VM using SSH.

  2. Run the following commands:

     sudo apt-get update
     sudo apt-get install nginx -y
    

  3. Once installed, you can start and manage the Nginx server.


Task 8: Host a Simple Website on a VM

Hosting a simple static website is a great way to get started with Compute Engine. Here’s how to use a VM to host a website.

Steps:

  1. SSH into your VM Instance by following the steps in Task-6.

  2. Install Nginx or Apache by following steps in Task-7 or use the code below.

     sudo apt-get update
     sudo apt-get install nginx -y
     sudo apt-get install apache2 -y
    
  3. Get back to the Compute Engine > VM Instances.

  4. Now click on Instance External IP to host the website.

  5. The website can now be viewed in a new browser tab.

Task 9: Create and Attach a Persistent Disk

If additional storage is needed for a VM, a persistent disk can be created and attached at any time.

Steps:

  1. Go to Compute Engine > Disks and click Create Disk.

  2. Define the size, type, and region for the disk.

  3. Click Create.

  4. Once created, go to VM Instances, select your VM Instance, and choose Edit.

  5. Scroll down to Additional Disks, click Attach Existing Disk, and select the disk you created.

  6. click SAVE, again click SAVE.

This will add an additional disk to an existing VM Instance.


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!

0
Subscribe to my newsletter

Read articles from Hridhi Kumari directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Hridhi Kumari
Hridhi Kumari