DEV Community

Cover image for GCP Essentials :: Compute Engine
Gurkirat Singh
Gurkirat Singh

Posted on

GCP Essentials :: Compute Engine

Hello everyone,

Among all of other services that I would be discussing in further posts, Virtual Machine may be the most familiar and common.

In this I will discuss about the Compute Engine service of Google Cloud Platform which is the service for spinning up a vps on GCP.

One of the nice things about virtual machines is that they have the power and generality of a full-fledged operating system. You can flexibly configure a VPS pretty much like you configure your PC, deciding CPU, memory (type and size) and storage (types and size).

You will also learn configuring the vpn and firewall to make your vps even more secure.

Ohk so if you coming from some other cloud service provider, let me amaze you with this: The VPC networks that you define have global scope. They can have subnets in any GCP region worldwide and subnets can span the zones that make up a region.

This feature let you create your own network configuration and use it as you wish.

Not only this but you can dynamically increase the size of a subnet in a custom network by expanding the range of IP addresses allocated to it. Doing that doesn't affect already configured VMs.

You can find the created instances here:

in gcloud

gcloud compute instances list --project=<PROJECT-ID>
Enter fullscreen mode Exit fullscreen mode

If you not created any instances, you will see the dashboard as above.

So while creating the instances, you will see the 4 types of instances.

  • General Purpose : Hosting static website or simple webapps
  • Compute Optimized : High quality dedicated CPUs
  • Memory Optimized : High quality dedicated RAM with more space
  • GPU : Add the Graphical Processing Units for deploying / training machine learning applications

I will be choosing General Purpose E2 Series and e2-medium machine for deployment.

Then in base image and disk space, I have chosen the following

NOTE: If you want you instance to access the google apis, select second or third option based on your architecture

Currently I will be using the default access.

Most of the time you will be deploying a web application on the server. If that is the case, check the firewall rules based on type of traffic you will be receiving

I will be selecting the HTTP rule for now.

Recheck everything and click "Create" button. Give some time to created and boot the instance.

To create the same instance via gcloud sdk execute the following command

gcloud beta compute --project=<PROJECT-ID> instances create myinstace --zone=europe-west2-c --machine-type=e2-medium --subnet=default --network-tier=PREMIUM --maintenance-policy=MIGRATE --service-account=<YOUR-SERVICE-ACCOUNT> --scopes=,,,,, --tags=http-server --image=ubuntu-2004-focal-v20201211 --image-project=ubuntu-os-cloud --boot-disk-size=30GB --boot-disk-type=pd-standard --boot-disk-device-name=myinstace --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
Enter fullscreen mode Exit fullscreen mode

and execute this command to add the HTTP rule for the instance

gcloud compute --project=<PROJECT-ID> firewall-rules create default-allow-http --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:80 --source-ranges= --target-tags=http-server
Enter fullscreen mode Exit fullscreen mode

Once it's created, you need the private key to access the VPC using ssh. The easiest way to connect to the server is gcloud. It will created the SSH keys automatically (if doesn't exists) and then create

gcloud beta compute ssh --zone <ZONE-ID> <INSTANCE-NAME> --project <PROJECT-ID>
Enter fullscreen mode Exit fullscreen mode

You can also connect to the instance from browser console. Click on the VPC you want to connect then click "Open in Browser"

NOTE: The default username that is created while instance creation is ubuntu

Since you might be a windows user or if you are linux user, gcloud will create the current logged in user in your VPC. So I personally recommend you to use the in-browser console for accessing the VPC. It will create the same username from every system you will access it.


  1. Deploying Compute Engine via gcloud
  2. Managing Firewall Rules for VPC
  3. Types of Machines and Their Configurations

I am waiting to see what have you deployed on your compute engine and how you are using it. Hit me up at the following

Top comments (0)