Summary
Ok, so you have been developing a nice script or application, and it's now working just you we want it to, that's great! But it's also not enough... you need to host it somewhere!
There are many options to host your app, but we'll focus on GCP Compute Engine because it offers a lot of freedom.
An important remark that is always valid is that we don't want to spend money unnecessarily, so keeping costs as low as possible is absolutely desirable, with extra points for keeping costs to actually zero.
Many tutorials (pretty much all the ones that I found so far) propose to use the free trial that GCP offers, but that is a limited amount of money during a limited period of time, so it's only useful for first time users and for short timed projects, so if you've used that up already (I certainly have), it's not really an option for you anymore.
Therefore, in this post I'll describe how to spin up a VM using GCP Compute Engine, and keep it within the free tier so it's completely free. And I don't mean using your free trial credits to pay for the VM, which is virtually free but only for a given time until those credits run out. I mean a VM that will cost nothing to keep it running for as long as we need it to.
NOTE: I'll assume that you're starting from scratch regarding Google Cloud Platform. For instance, I'll include the creation of a new GCP Project as a step, but of course you can just use an already existing project if you have one. Same for other things, but you should be able to adapt to each case only needing a bit of common sense.
Why a Linux VM
Like I said, there are countless options to host your app, way too many to even mention here a meaningful fraction of them, but whenever possible I try to always use a Linux VM.
The reasons for my choice are also many, but I can enumerate some:
- It's Linux, and I love Linux. Every other solution or service will be a virtualization on top of a Linux machine, so being able to manage a Linux VM is a great skill to have.
- I can host many applications in the same VM, so I don't need to have many services running in GCP or any other cloud, just one VM is good enough for many solutions (until it runs out of CPU, RAM, or disk space, of course).
- I can have complete control over the machine, something that's not available with other services with high virtualization like Cloud Functions, App Engine, Cloud Run, etc.
- I can still implement different levels of virtualization if needed using Docker, so I don't lose anything in that regard.
Billing
Even when using only the free tier, you need to create a GCP Project and a Billing Account, because that is a simply pre-requisite to enable the Compute Engine (VMs) service in GCP.
On top of that, the Billing Account will require that you add a Credit or Debit card to it, because that is a pre-requisite to create a Billing Account.
No need to worry, however, because everything is prepared to avoid being charged accidentally in case we make a mistake when setting up the VM.
Create a Billing Account
The first step is to create the billing account.
Just go to "Billing" > "Billing Accounts", click on "Add Billing Account" and follow the given steps (it's quite straight forward, but note that here you'll need to add your credit or debit card details):
Again: we'll set up a Billing Account with a credit or debit card because it's a requisite to use some GCP services (like Compute Engine), but we'll remain within the free tier limits so we won't be charged.
And even if we make a mistake and surpass the free tier limits, we'll assign a very low budget to the billing account, and set up alerts so we get notified immediately if we start spending any money.
After creating the Billing Account, you should see it listed as follows:
Let's set up a budget and some alerts to avoid spending money by mistake.
Clicking on the Billing Account takes us to the Billing Account overview:
Then go to "Budgets & alerts", click on "Create Budget" and follow the steps to set up a very low budget (10 USD is low enough in my opinion, but you can choose something different matching your idea of "very low") and some alerts (I use 50%, 90%, and 100%):
This way if during any future month we start spending money by mistake, and reach 5 USD, we'll get a notification via
email and we can go to our GCP Project and change or stop whatever service is spending money.
Besides, we can always just go to our Billing Account overview and manually check if it's spending any money or not.
Now we have to assign this billing account to the project, so go to Billing > Projects, and you'll see your GCP project
there, which will have the billing disabled because so far no Billing Account has been assigned to it:
To assign the billing account to it, click on the 3 dots, and click on Change Billing, and follow the steps:
And that's it!
We can now enable services that require Billing to be active, like Compute Engine.
Spin up a VM
The GCP free tier specifications for Compute Engine might be changed by Google eventually, so by all means do check them
out in the official docs.
At the moment they are like this:
So we can spin up an e2-micro VM with a 30 GB standard persistent disk.
First, we need to enable the Compute Engine service:
And then create a VM by clicking on "Create Instance":
Follow the steps by selecting all the free options according to what is currently free,
and once that is finished the VM Instance will be listed in "Compute Engine" > "VM Instances" (as can be seen in the
picture above, blurred).
And that's it! The VM will be created and listed in the Compute Engine overview.
Conclusion
Here I showed you how to, starting from scratch, create a GCP project, add a Billing Account to it, and spin up a free Linux VM using GCP Compute Engine.
The steps are quite easy and simple to follow, but do take into account that Google is prone to change things here and there as time passes, so if some time has passed between me writing this (December 2022) and you reading it, go and check the official documentation to see that everything is still valid (I left links to GCP official docs here and there throughout the post).
And that's it, the VM is ready to be used!
Top comments (1)
Very Informative. đź‘Ź
I created an article a while back regarding VMs on Azure using SSH as well as RDP for GUI based VMs and hosting websites cost free on them. Do check that out as well.
huzzaifaasim.medium.com/a-beginner...