Google Cloud Create Simple GCP GCE VM Instance
Step-01: Introduction¶
- We will learn the following concepts as part of this section
- How to create Linux VM Instnace in Google Cloud Platform ?
- How to connect to Linux VM Instnace in GCP using SSH via Browser ?
- What are various settings available on SSH via Browser ?
- How to install a simple webserver on GCP VM Instance and access those sample pages on webserver via Browser using GCP External IP ?
- How to Manage VM Instances (Stop / Start / Suspend / Resume / Reset / Delete etc)?
Step-02: Create VM Instance¶
- Enable
Google Compute Engine API - Go to Virtual Machines -> VM Instances -> Create Instance -> New VM Instance -> Provide required details
- Name: demo1-vm
- Labels: environment: dev
- Region: us-central1
- Zone: us-central1-a
- Machine Configuration:
- Series: E2
- Machine Type: e2-micro
- Availability Policies:
- VM Provisioning Model: Standard
- Display Device: checked
- Confidential VM Service: unchecked (leave to default)
- Container: unchecked (leave to default)
- Boot Disk: Leave to defaults
- Identity and API Access:
- Service Account: Compute Engine default Service Account
- Access Scopes: Allow default Access
- Firewall
- Allow HTTP Traffic
- Advanced Options: We will learn these later in detail, lot to discuss for each and every option
- Click on Create
Step-03: Discuss about newly created VM (very high level)¶
- What are VM Filters ?
- What is VM Internal IP ?
- What is VM External IP ?
- How to connect to Linux VM ?
Step-04: Connect to Linux VM Instance using SSH¶
- Go to VM Instances -> demo1-vm -> SSH -> Open in browser window
- Understand what happens in background when opening SSH Connection via browser
- SSH Keys transferred to VM
- Verify in
.ssh/authorized_keysfile - We will talk more about
SSH Keysin that respective demo in detail with all options
Step-05: Create / Review webserver-install.sh¶
- Create a simple script named
webserver-install.shand put the below contnent and run it - webserver-install.sh
#!/bin/bash sudo apt install -y telnet sudo apt install -y nginx sudo systemctl enable nginx sudo chmod -R 755 /var/www/html HOSTNAME=$(hostname) sudo echo "<!DOCTYPE html> <html> <body style='background-color:rgb(250, 210, 210);'> <h1>Welcome to StackSimplify - WebVM App1 </h1> <p><strong>VM Hostname:</strong> $HOSTNAME</p> <p><strong>VM IP Address:</strong> $(hostname -I)</p> <p><strong>Application Version:</strong> V1</p> <p>Google Cloud Platform - Demos</p> </body></html>" | sudo tee /var/www/html/index.html
Step-06: Understand SSH Settings when connected via Browser¶
- Color Themes
- Text Size
- Font
- Copy Settings
- Key Board Shortcuts
- Upload File
- Download File
- Instance Details
- New Connection to VM
- Change Linux Username
Step-07: Upload and Run the webserver install script¶
# Run the commands
hostname
ip -s addr
Observation:
1. make a note of IP address and hostname
# Upload file
Upload file webserver-install.sh
# Give Permissions
chmod 755 webserver-install.sh
# Install Webserver using script
./webserver-install.sh
# Verify Files
cd /var/www/html
ls
cd app1
ls
Step-08: Access Webserver Pages¶
Step-10: Managing VM Instnace - VM Actions¶
- VM Stop: Stop shuts down the instance. If the shutdown doesn't complete within 90 seconds, the instance is forced to halt. This can lead to file-system corruption.
- VM Start: Start the VM
- VM Suspend: The instance will preserve its running state, similar to closing a laptop. You'll be billed for storage of the suspended VM state and any persistent disks it uses. The instance won't be accessible while it's being suspended, which may take a few minutes.
- VM Resume: Resume the VM from suspended state
- VM Reset: Reset performs a hard reset on the instance, which wipes the memory contents of the machine and resets the virtual machine to its initial state. This can lead to filesystem corruption.
- VM Delete: Delete the VM instance
- View Network Details: It will take us to Network Interface Details of a VM
- Review
Network Interface details - Review
VM Instance details - Review
Firewall Rules - Review
Network Analysis - Create new Machine Image: We will have a dedicated demo for this
- View logs: We will have a dedicated demos for this
- View Monitoring: We will have a dedicated demo for this
- Verify VM Instance ID details
Step-11: Perform VM Action - Suspend and Resume¶
- Go to VM Instances -> demo1-vm -> Actions -> Suspend
- We should see suspend action is success
- Go to VM Instances -> demo1-vm -> Actions -> Start / Resume
- Exteral IP before and after "suspend and resume" action will vary (Its a Ephemeral IP Address - NOT STATIC)
Step-12: Perform VM Action - Reset¶
- Go to VM Instances -> demo1-vm -> Actions -> Reset
- Just memory wipes, any data in system memory will be reset
Step-13: Review VM Settings after Creation¶
- Go to VM Instances -> demo1-vm
- Details Tab
- Observability Tab
- Screenshots Tab
Step-14: Stop VM to avoid charges¶
- Go to VM Instances -> demo1-vm -> Stop
- Verify Notifications at the top right corner.
- Additional Observation: When VM is stopped, Public IP or External IP is released
Step-15: Where is the Boot Disk located for the demo1-vm¶
- Go to Compute Engine -> Storage -> Disks -> demo1-vm
- Review
- DETAILS Tab
- MONITORING Tab
References¶
🎉 New Course
Ultimate DevOps Real-World Project Implementation on AWS
$15.99
$84.99
81% OFF
DEVOPS2026FEB
Enroll Now on Udemy
🎉 Offer