Creating a VM

Compute Engine

Compute Engine provides virtual machines (IaaS). You choose the machine type, OS image, disk and network, and you manage everything inside the VM (updates, software, security).

Create and Connect

Example

gcloud compute instances create web-1 \
  --zone=asia-south1-a \
  --machine-type=e2-small \
  --image-family=debian-12 --image-project=debian-cloud \
  --boot-disk-size=20GB \
  --tags=http-server

gcloud compute ssh web-1 --zone=asia-south1-a

Example output

Created [https://www.googleapis.com/compute/v1/projects/shop-dev-1234/zones/asia-south1-a/instances/web-1].
NAME   ZONE           MACHINE_TYPE  INTERNAL_IP  EXTERNAL_IP    STATUS
web-1  asia-south1-a  e2-small      10.160.0.2   34.100.12.34   RUNNING

Startup Scripts

gcloud compute instances create web-2 --zone=asia-south1-a --tags=http-server \
  --metadata=startup-script='#! /bin/bash
apt-get update && apt-get install -y nginx
echo "Hello from $(hostname)" > /var/www/html/index.html'

Tip: For repeatable fleets, use instance templates and managed instance groups (autoscaling and auto-healing).