Introduction
Google Compute Engine lets you create customizable virtual machines in the cloud. This tutorial walks you through deploying your first instance step by step. You will learn to use the gcloud CLI for precise, reproducible control. This approach suits developers and system administrators who want to automate their deployments.
Prerequisites
- Google Cloud account with billing enabled
- Basic command-line knowledge
- Google Cloud SDK installed on your machine
Installing the Google Cloud SDK
curl https://sdk.cloud.google.com | bash
exec -l $SHELL
gcloud initThis command downloads and installs the Google Cloud SDK. The gcloud init command launches the initial configuration wizard to connect your account.
Authentication and Project Setup
gcloud auth login
gcloud config set project MON-PROJET-IDAuthenticate with Google Cloud and set the active project. Replace MON-PROJET-ID with your actual project ID.
Creating the VM Instance
gcloud compute instances create mon-premiere-vm \
--zone=europe-west1-b \
--machine-type=e2-micro \
--image-family=debian-11 \
--image-project=debian-cloud \
--tags=http-serverThis command creates an e2-micro instance running Debian 11 in the europe-west1-b zone. The http-server tag opens port 80 through the firewall.
SSH Connection to the Instance
gcloud compute ssh mon-premiere-vm --zone=europe-west1-bThis command establishes a secure SSH connection to your instance without manual key management.
Firewall Configuration
gcloud compute firewall-rules create allow-http \
--allow tcp:80 \
--target-tags=http-server \
--direction=INGRESSThis rule allows incoming HTTP traffic on port 80 for all instances tagged with http-server.
Best Practices
- Always choose the zone closest to your users
- Use machine types suited to your workload
- Enable automatic security updates
- Name resources clearly with consistent conventions
Common Errors
- Forgetting to specify the zone in each command
- Using an overly expensive machine type for testing
- Neglecting firewall rule configuration
- Not enabling the Compute Engine API before use
Going Further
Discover our complete Google Cloud courses to deepen your knowledge of automation and production best practices.