How to run VS code using Google Cloud

Creating Your VM in Google Cloud

To begin, open up your google cloud console and go to the compute engine section and click on the create instance button.

Next, name your instance whatever you want and select the region closest to you. For me that is the London Europe Region.

Then move on to the machine configuration where you will want to select the E2 CPU with a custom configuration of 2 vCPU cores and 1GB of memory.

Next move on to the firewall settings where you will want to select both the HTTP and HTTPS check boxes in order to allow you to be able to connect.

After this select the networking tab and edit the network interface.

In order to be able to connect from the same external IP each time and to be able to point a custom domain to your cloud instance we need to add a static external IP instead of an epithermal external IP (random).

To do this open the drop down menu by selecting the External IP drop down menu.

Click on the Create IP address in order to reserve your static address.

Name your static IP and select the Network Service Tier as standard. The region will be automatically populated with same region as the VM instance. Once done click reserve to confirm the changes.

Click on create instance to start your VM. You will be billed as soon as you start your instance, if you are using the Google Cloud free trial this will use your credits and will then charge your card.

You will have to wait a few minutes while the machine spins up and once completed click on SSH to open up the remote terminal.

This will open up the traditional linux terminal in a new tab where we can now begin our install proccess.

Installing VS Code

For this we will be using the open source tool code-server. To install this run the command below.

curl -fsSL | sh -s -- --dry-run

We can now run the VS Code server by running and accessing it via the static IP address we set earlier. This will run unprotected on port 8080.

sudo code-server

This is not advised however due to the instance being unprotected and will expose itself to the world. This is crucial, as someone can completely take over your machine using the VC Code terminal.

In the next post we will go through how to prevent this by using a reverse proxy via Apache2.

Leave a comment

Your email address will not be published. Required fields are marked *