I develop my hobby projects solely on remote VMs because my office laptop is on Windows and has a lot of restrictions due to enterprise policies. I have managed to get VS-Code and SSH installed so that I can get going and now remote VM is my primary development station like a personal desktop.
I’m hosted on Google Cloud and very soon I exhausted my GCP credits. The always free tier instance type f1-micro
is plain useless when it comes to development and running a decent sized VM can become pretty costly.
Preeptible instances offer a very good option in terms of price, prices of preemptible instances are less than 1/3rd of the normal price. But the downside is that they terminate in 24 hours and need to be restarted.
Step 1 - Create a GCP account and exhaust the free credits
Step 2 - Set up f1-micro
instance with ubuntu
Step 3 - Create a preemptible instance (I’m surpised there is no visual instruction on the internet so here is how you launch a instance from your GCP console. -)
Go to your gcp console -> Compute Engine -> Create Instance
I use e2-micro
instance and it is more than enough for most of my needs, If I have to do any data science stuff then I either use Google Notebook or change the instance type to n1 or n2 type instance. For e2.micro, you wil spend around 2.7$ monthly which is around 200 rupees.
Step 4 - Set a cron job in your always fre instance for starting the VM every 5 minutes
Open terminal in your laptop/PC and run below (Assuming you have Google cloud sdk installed and authenticated)
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
desktop asia-southeast1-b e2-micro true xx.xxx.x.x xx.xxx.xxx.xxx RUNNING
alwaysfree us-central1-a f1-micro xx.xxx.x.x xx.xxx.xxx.xxx RUNNING
$ gcloud compute ssh alwaysfree
name@alwaysfree:~$ crontab -e
# Insert this at the bottom
PATH=$PATH:/snap/bin
*/5 * * * * gcloud compute instances start desktop --zone asia-southeast1-b
That is it, now every 5 minutes cron will try to switch on the VM, if it is already on, nothing happens.
There are multiple ways to do this, but the current method is working out great for me.