Scaled VM: Part 2. Shared FS and VM Instances

Valentyn Shybanov
3 min readSep 23, 2017

--

How to create simple setup with “scaled VM” approach in Google Cloud Platform.

In previous article I’ve described the approach of “scaled VM”: scaling solution with simple file sharing option for hosting simple PHP-based web sites. Here I will describe step-by-step actions how to setup this configuration.

[Part 1: introduction] [Part 2: FS/VM] [Part 3: Web] [Part 4: Load Balancer]

1. Single Node Filer

After analysing possible options (Persistence storage, GlusterFS) I’ve decided to use single node filter option. Fortunately, within Google Cloud Platform you can install within couple of clicks by using Google Cloud Launcher by running “Single Node Filer” deployment.

I’ve reduced storage size from 1000Gb to 200Gb and instance size to single core 4Gb RAM. It will cost approx. $25/month.

After deployment complete you should have something like:

2. Instance template (iteration 1: access to shared FS)

So you have file system node. Now let’s create instance template that will be used in managed instance group. This template will be used each time new VM is created (e.g. while scaling).

The process of creating is quite simple — you just go to “Compute Engine/Instance templates” and create new one. Here are some important things:

  • It is better to put instances in same zone as filer node.
  • You should not create powerful instances. Remember — they will be scaled upon needed. I preferring to have average $20-$25/month instance.

But the most important is “Management, disks, networking, SSH keys” section that is located just above “Create” button:

Open it and under “Management” add these lines (change “singlefs-vm-1” to the name of filer node):

sudo DEBIAN_FRONTEND=noninteractive apt-get -y update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install nfs-common
sudo mount -t nfs singlefs-1-vm:/data /mnt

After that you can create an instance template and then go to Instance Groups and create one based on newly created template.

Important points here:

  • Use “Single-zone” option (you don’t want files to be served with NFS across zones). And single filer is not “high-available” in its nature
  • Use “Managed instance group”. The point of what you’re doing is to have auto scaling. And it is possible when instance group is managed.
  • Choose template you’ve created
  • Enable “Autoscale” option. For now, leave scaling based on CPU (Later we’ll change to HTTP). And leave without health check (later will also add it).

When you’ll done in a while you should have your instance group up and running. At the bottom of the screen you should see spawning instance. When it’s ready, click “SSH” button to login to the instance and test shared file storage.

To test you can do following:

  • Create file in shared storage:
$ echo “Hello” > /mnt/test.txt
  • Replace instances: in “Cloud Console/Compute/Instance Groups” click “Rolling restart/replace”.
  • Open SSH in newly create instance and check are the files still there

If you’ll see “Hello” there, everything is ok.

In the next part I’ll explain how install Apache/PHP.

--

--