I have created a detailed blog post for Google Compute Engine (GCE) aimed at preparing for the GCP Associate Cloud Engineer certification:
Table of Contents
Google Compute Engine (GCE) is one of the foundational services of Google Cloud Platform (GCP), enabling you to run virtual machines (VMs) on Google’s infrastructure. If you’re preparing for the GCP Associate Cloud Engineer certification, understanding GCE is critical.
In this guide, we’ll walk through essential concepts and practical steps with screenshots and code snippets, covering the following:
- Logging in to GCP
- Navigating to VM Instances
- Creating Your First Virtual Machine in GCP
- Understanding Machine Types and Images in GCE
- Installing an HTTP Web Server on a GCE Virtual Machine
- Internal and External IPs Explained
- Creating a VM with a Startup Script
- Simplifying VM Creation with Instance Templates
- Reducing Time with Custom Images
1. Logging in to GCP
- Navigate to Google Cloud Console.
- Log in with your credentials.
- If prompted, set up a new project or select an existing project.
2. Navigating to VM Instances
- In the Navigation Menu, search for “Compute Engine” and click VM instances.
- Click Enable if prompted to activate the Compute Engine API.
3. Creating Your First Virtual Machine in GCP
- Click Create Instance.
- Fill in the details:
- Name:
my-first-instance
- Region/Zone: Choose one close to your users.
- Machine type: Start with
e2-micro
for practice.
- Name:
- Boot Disk: Select an image (e.g., Debian 11 or Ubuntu 20.04).
- Click Create.
4. Understanding Machine Types and Images in GCE
- Machine Types:
GCP offers flexible machine types:- General-purpose: e2, n1 series for typical workloads.
- Compute-optimized: c2 series for CPU-intensive tasks.
- Memory-optimized: m2 series for RAM-heavy applications.
- For example: Machine type like e2-highcpu-2 where e2 means the type, highcpu is class and last 2 is for cpu (2 core)
- Images:
Predefined OS images include Debian, Ubuntu, CentOS, Windows Server, etc. You can also use custom or marketplace images.
5. Installing an HTTP Web Server on a GCE Virtual Machine
- SSH into the instance:
gcloud compute ssh my-first-instance
- Update packages and install Apache:
sudo apt update sudo apt install apache2 -y
- Test by accessing the external IP of your VM in a browser.
Screenshot: ![Show the Apache default page after installation]
6. Internal and External IPs Explained
- Internal IP: Private IP within the VPC. Used for communication between instances.
- External IP: Public-facing IP for accessing the VM over the internet.
You can find these details in the VM instance’s Details page.
Code Snippet:
gcloud compute instances list
7. Creating a VM with a Startup Script
- Add a startup script during VM creation under the Management tab:
#! /bin/bash
apt update
apt install -y apache2 systemctl start apache2
8. Simplifying VM Creation with Instance Templates
- Go to Instance Templates in the Compute Engine section.
- Click Create Template, and predefine:
- Machine type.
- Boot disk.
- Metadata (e.g., startup scripts).
- Use the template to create consistent VMs quickly.
9. Reducing Time with Custom Images
- Configure a VM with your required settings and install necessary software.
- Create a custom image
- Use this custom image in new VM instances for faster deployment.
gcloud compute images create my-custom-image \ --source-disk=my-first-instance \ --source-disk-zone=us-central1-a
Google Compute Engine is a versatile and essential service for deploying VMs on GCP. By mastering these steps, you’ll not only be prepared for the GCP Associate Cloud Engineer exam but also capable of managing real-world deployments efficiently.