10 - Compute Engine VMs - Launching Virtual Servers
Welcome to Day 10 of Learn GCP in 30 Days! Yesterday, you learned how firewall rules act as digital bouncers. Today, we build the actual computer inside your network: GCP Compute Engine Virtual Machines (VMs).
Today's Goal Today, you will learn how to create and launch your very first virtual computer inside Google Cloud, understand how CPU, RAM, and Disk work together, see what happens when you stop a server, and serve a live web page to the internet!
The Core Problem: Buying Computers vs. Renting Virtual Servers
Imagine you want to launch a new website or mobile app for your business.
What Existed Previously:
In the past, if you wanted to launch a website, you had to go to a physical computer store, buy a desktop computer tower, bring it home, plug in power cables and internet wires, install an operating system (like Linux or Windows) using a USB flash drive, and leave it running in your bedroom 24 hours a day.
Why did you have to keep it turned on 24/7? Because your computer was the server!
Whenever a customer anywhere in the world typed your website address in their browser, their request traveled across the internet directly into your home computer. Your home system was responsible for receiving that request, reading the files, and serving back the web pages or images the customer was looking for. If you turned off your home computer, no one could visit your website!
Problems Faced:
- 💸 Expensive Upfront Cost: Buying a physical desktop tower cost hundreds or thousands of dollars before serving a single customer.
- ⚡ 24/7 Home Burden: Leaving a home computer running constantly consumed electricity, created noisy fan spinning in your room, and crashed your website whenever your home power or Wi-Fi dropped out.
- 🐌 Limited Home Internet Speed: A standard home internet connection could only handle a few visitors at a time before getting slow and crashing under load.
How Present Technology Solves It:
Google Cloud gives you Compute Engine.
A Virtual Machine (VM) is a complete computer system—just like your personal laptop or desktop—running inside Google's cloud data center, which you can run and control remotely over the internet!
Instead of keeping your personal computer running in your bedroom, Google's Virtual Machine sits in a ultra-fast data center. It stays online 24/7 to receive incoming requests from users around the world and serve back whatever web pages or data they are looking for—with zero noise, zero home electricity bills, and massive internet bandwidth!
🧩 How a Virtual Machine Works: CPU, RAM, and Disk Explained
To understand how a Virtual Machine operates, think of it as a 3-part working office:
1. vCPU (The Worker's Brain)
- What it does: The vCPU (Virtual CPU) is the digital brain of your computer. It performs calculations, executes code instructions, and processes logic.
- Real-Life Analogy: Like a smart office worker thinking and doing math in their head.
2. RAM / Memory (The Temporary Desk Space)
- What it does: RAM is ultra-fast, temporary working memory. When you start Nginx or a database, the system loads active files into RAM so the vCPU can read them instantly without waiting.
- Real-Life Analogy: Like the surface of your office desk. Everything you are actively working on right now sits on your desk for instant reach.
- Key Property: RAM is volatile. When power turns off, everything sitting on the desk is wiped completely clean!
3. Boot Disk / Hard Drive (The Permanent Filing Cabinet)
- What it does: The Disk (SSD or HDD) is non-volatile permanent storage. It holds your Linux operating system, installed applications, website files (
index.html), and databases. - Real-Life Analogy: Like a metal filing cabinet in your office. Even when you lock up the office and turn off the lights at night, all files inside the cabinet stay safely stored!
🛑 What Happens to Each Component When You STOP a VM?
When you click STOP on your Virtual Machine in Google Cloud:
| VM Component | What Happens When Stopped? | Does it Cost Money While Stopped? |
|---|---|---|
| 🧠 vCPU (Brain) | Shuts down completely and pauses calculations. | 💸 $0.00 (Compute billing stops immediately!). |
| 🗄️ RAM (Memory) | Cleared completely to zero. Temporary cache resets. | 💸 $0.00 (RAM billing stops immediately!). |
| 💾 Boot Disk (Hard Drive) | Stays 100% saved in Google Cloud! Your files, OS, and code remain intact. | 🪙 You pay a few pennies a month to store the saved disk. |
Stop vs. Delete Summary
- Stopping a VM: Turns off CPU & RAM ($0 compute billing), but keeps your hard drive saved so you can turn the computer back on anytime.
- Deleting a VM: Erases CPU, RAM, AND the Hard Drive completely, dropping your total cost to $0.00!
Real-World Analogy: Customizing a Rental Computer
Imagine walking up to the counter of a modern Computer Rental Shop.
The shop assistant hands you a simple 5-step order form to build your temporary rental computer:
Once you submit the form, Google instantly builds a virtual computer matching your exact specs and gives you remote control access over the internet to manage it!
🔑 Everyday Cloud Terms Explained in Plain English
Let's break down essential virtual machine terms into everyday concepts:
1. Virtual Machine (VM)
A Virtual Machine (VM) is a computer system—just like your personal laptop or desktop—running inside Google's cloud data centers. You control and run this virtual machine remotely over the internet, and it receives incoming user requests 24/7 to serve web pages, applications, or files to visitors around the world.
2. What is Nginx & What is it Useful For?
💡 The Front Desk Receptionist Analogy: Imagine your VM is a physical shop building, and Linux is the floor space. Nginx (pronounced "Engine-X") is the Front Desk Receptionist sitting at Door 80 (HTTP).
- What it does: When a visitor types your VM's IP address in their browser, Nginx greets the visitor, fetches your website files (like
index.html), and hands them back to the visitor's browser screen! - Why it is useful:
- Web Server: Serves website files (HTML, CSS, images) to thousands of users simultaneously.
- Ultra-Fast & Lightweight: Handles high traffic using very little RAM memory.
- Traffic Manager (Reverse Proxy): Forwards requests safely to your Node.js, Python, or Java apps.
3. SSH (Secure Shell) - The Remote Control Window
SSH is a secure encrypted text doorway that lets you log into your Linux server remotely over the internet.
- In GCP, you don't need to plug a physical monitor or keyboard into the cloud computer.
- You simply click a single "SSH" button in your web browser, or type
gcloud compute ssh my-first-vmin Cloud Shell, and a command terminal opens up connected directly to your server!
🧪 Hands-on Lab Activity: Launching Your First Web Server VM
You can create your VM using either the Web Console Website (UI) or Cloud Shell (CLI). Pick whichever method you prefer!
Why asia-south1-a (Mumbai)?
Choosing a data center region close to your primary audience (e.g. asia-south1-a in Mumbai, India) ensures ultra-low network latency (faster load times) for your website visitors!
Activity 1: Launch a Web Server VM
Method A: Web Console Website (UI Click-by-Click)
- Log into console.cloud.google.com.
- Open the left menu
☰Click Compute Engine Click VM instances. - Click the Create Instance button at the top bar.
- Fill in basic details:
- Name:
my-first-vm - Region:
asia-south1 (Mumbai)| Zone:asia-south1-a - Machine Configuration: Series
E2, Machine typee2-micro.
- Name:
- Open Firewall Port 80:
- In the left side sub-menu of the Create page, click Networking.
- Look under Firewall ("Select firewall rules to allow specific network traffic from the Internet...").
- Check the box for Allow HTTP traffic.
- Paste Startup Script:
- Scroll down and click Advanced options click Management (or Automation).
- If you see a Startup script box, paste the code below.
- Alternative: Under Metadata, click Add item set Key =
startup-scriptand Value = paste the code below:bash#!/bin/bash apt-get update apt-get install -y nginx echo "<h1>Hello World from my First GCP Virtual Machine in Mumbai!</h1>" > /var/www/html/index.html
- Click Create! In 20 seconds, your VM is ready.
Method B: Cloud Shell CLI (Command Terminal)
- Click the Activate Cloud Shell (
>_) icon at the top right of your GCP Console. - Open Firewall Port 80:
bash
gcloud compute firewall-rules create allow-http-web \ --direction=INGRESS --priority=1000 --action=ALLOW \ --rules=tcp:80 --target-tags=http-server 2>/dev/null || true - Create the VM:
bash
gcloud compute instances create my-first-vm \ --zone=asia-south1-a \ --machine-type=e2-micro \ --tags=http-server \ --metadata=startup-script='#!/bin/bash apt-get update apt-get install -y nginx echo "<h1>Hello World from my First GCP Virtual Machine in Mumbai!</h1>" > /var/www/html/index.html'
Activity 2: Test Your Live Web Server
- Find the EXTERNAL_IP of
my-first-vm(listed in the VM instances table or Cloud Shell output). - Open a new tab in your web browser, type
http://YOUR_EXTERNAL_IP(e.g.http://34.180.39.76), and press Enter. - Your browser sends an HTTP request over the internet to
my-first-vm. Nginx receives the request and serves back the web page saying: "Hello World from my First GCP Virtual Machine in Mumbai!"
Troubleshooting: Why is entering the IP showing nothing or failing to load? If your browser shows Site cannot be reached or loading wheel spins forever, check these 4 common fixes:
- Typing
https://instead ofhttp://: Modern browsers (Chrome/Edge) automatically tryhttps://(Port 443). Nginx is listening on Port 80 (http://). Make sure you explicitly typehttp://in front of your IP address in the URL bar! - Missing Firewall Rule / Checkbox: If you forgot to check "Allow HTTP traffic" or run the firewall command, Port 80 is blocked!
- Copying Internal IP instead of External IP: Make sure you copy the External IP (e.g.
34.180.x.x), NOT the Internal IP (10.x.x.x). Internal IPs only work inside GCP networks! - Running Linux commands inside Cloud Shell instead of SSH: Running
sudo systemctl status nginxinside Cloud Shell will fail with System has not been booted with systemd. You must SSH intomy-first-vmfirst!
Activity 3: Log into your VM using SSH
Cloud Shell CLI vs. SSH into VM (What's the Difference?)
- Cloud Shell Terminal (
>_): Like runningcmdon your management computer to manage Google Cloud (creating VMs, creating firewalls, deleting projects). - SSH Terminal: Like running
cmdINSIDE the remote virtual server you rented from GCP (installing Linux software, checking Nginx status, editing website files).
Method A: Web Console Website (UI 1-Click)
- Go to Compute Engine VM instances.
- Next to
my-first-vm, click the SSH button under the Connect column. - A popup browser window opens connected directly inside your Linux server!
Method B: Cloud Shell CLI
- Run
gcloud compute ssh my-first-vm --zone=asia-south1-a. - (If prompted, press Y to continue and press Enter for any passphrase prompts).
Once inside the VM SSH prompt (manikantasandula@my-first-vm:~$), run sudo systemctl status nginx to verify Nginx is active (active (running) in green text), then type exit to disconnect.
🧹 Clean Up Step (Credit Safety Guarantee)
Delete your test VM and test firewall rule to keep your running costs at $0.00:
- Via Web Console UI: Check the box next to
my-first-vmClick Delete at the top bar. - Via Cloud Shell CLI:
bash
gcloud compute instances delete my-first-vm --zone=asia-south1-a --quiet gcloud compute firewall-rules delete allow-http-web --quiet
Credit Safety Reminder: Stop vs. Delete
- Stopping a VM: Pauses CPU and RAM billing, but you still pay a tiny fraction for stored hard drive space.
- Deleting a VM: Completely removes the computer and hard drive, dropping your running cost to $0.00!
Signal vs. Noise: Key Concepts & Noise Filter
Good to Know (Key Concepts)
- Virtual Machine (VM): A system like your computer running in the cloud that you control over the internet.
- vCPU: The digital brain calculating logic.
- RAM: Temporary fast desk space cleared when VM stops.
- Boot Disk: Permanent filing cabinet storage that stays saved when VM stops.
- Nginx: High-speed web server software acting as the front desk receptionist to serve web pages to visitors.
- Cloud Shell vs SSH: Cloud Shell manages GCP resources; SSH opens the terminal inside your VM server.
- Delete VM: Completely removes the VM so costs drop to $0.00.
Noise Filter (Don't Memorize)
- Do NOT try to memorize all 50+ machine family model codes (
c2d,m3,a2,n2d). You will pick simple general-purpose sizes likee2-microore2-medium. - Do NOT memorize Nginx C-code source configuration files—default Nginx settings work out of the box.
Common Doubts & Interview Traps
Q1: What happens to my website code on the hard drive if I stop my VM?
- Answer: Your website code and files on the hard drive stay 100% saved in Google Cloud! Only temporary RAM memory clears. When you start the VM back up, your files are right where you left them.
Q2: What is the difference between Cloud Shell and SSH into a VM?
- Answer: Cloud Shell is your management terminal to command GCP (creating/deleting VMs). SSH is the terminal doorway into your rented virtual server to run Linux software like Nginx.
Q3: What is the difference between Stopping a VM and Deleting a VM?
- Answer:
- Stopping a VM turns off CPU and RAM ($0 compute billing), but keeps your hard drive saved so you can turn the computer back on anytime.
- Deleting a VM destroys CPU, RAM, AND the Hard Drive completely, dropping your total cost to $0.00.
Daily Practice Drill & Self-Check
Test your understanding of today's lesson:
// Try answering these:
1. Which component inside a VM acts as the temporary working desk space and gets cleared to zero when you stop a VM: vCPU, RAM, or Boot Disk?
2. What is the difference between Cloud Shell terminal and SSH terminal?
3. When you stop a VM, what happens to your files saved on the Boot Disk?
💡 Click for Solutions
- RAM (Memory)! RAM is volatile temporary memory that clears when power turns off.
- Cloud Shell manages GCP resources (like
cmdon your laptop); SSH logs into your rented remote server to run Linux commands inside it! - They stay 100% saved in Google Cloud! You can start the VM back up anytime.
🎉 Awesome job! You have completed Day 10.
You now know how CPU, RAM, and Disk work together, what happens when you stop a VM, how to install Nginx, and how to serve live web pages using either the Web Console or Cloud Shell. Take a break, let today's concepts sink in, and come back tomorrow fresh!
Tomorrow on Day 11, we will learn about Machine Types and Cost Optimization so you know how to pick the right computer size and save up to 90% on server costs using Spot VMs!
← 09 - Firewall Rules and Traffic Control | Next Topic → 11 - Machine Types and Cost Optimization