Mounting Google Storage on an OpenVZ Debian Jessie container

So I have a few OpenVZ containers with Debian Jessie running on them. I needed to be able to move files from the container to Google Storage. Jumped on Google and started looking at my options. GCSFUSE was the answer I got.

Now as any documentation you get out there half of it works and half does not and you end up spending a lot of time searching for weird and wonderful errors. So this is what I found and what worked for me.

Firstly you need to enable access for the containers to the fuse file system on the host. On the Host system run the following commands:

modprobe fuse 
vzctl set VEID --devnodes fuse:rw --save

Where VEID is the veid of the container you want to give access to.

I spin up a new Debian Jessie container and run the following commands:

apt-get update
apt-get install sudo
apt-get install curl
apt-get install apt-transport-https

These packages are not installed by default so installing these gets the basic applications for the installation. Then we add the correct repository to apt for easy installation:

export GCSFUSE_REPO=gcsfuse-`lsb_release -c -s`
echo "deb http://packages.cloud.google.com/apt $GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

Then I install the gcsfuse package on the system.

apt-get update
apt-get install gcsfuse

Next we create the mount point where we want to mount our Google storage bucket.

mkdir /target/folder

There is a bug in Debian Jessie where the rights to the fuse device is not correct so we need to make sure we have the access we need:

chmod g+rw /dev/fuse

After this it is a good idea to do a good old reboot of the system to make sure everything starts up and works as expected. I have found a lot of forum posts where after all the setup, people were getting errors ( me included ) and a reboot of the system got everything working as expected.

Now if you have not done the setup on your Google cloud project, here is a quick rundown of what needs to be done.

  1. If you have not created a project on your Google Cloud Console, I would suggest popping over there and create it.
  2. Create your storage bucket.
  3. Create a Service Account and give it the role of Storage – Storage Object Creator
  4. With the service Account download the JSON key file.
  5. Remember to give the Service account access to your bucket or else you will get Authorisation errors.

The Steps above are well documented and a quick Google search will furnish you with what you need to know.

Make sure to copy your key file to your container.

This brings us to the moment of truth, as they say. Mounting the storage bucket to our file system:

gcsfuse --key-file /path/keyfile.json bucket-name /target/folder

At this point your Storage bucket should be mounted to your target folder and you can interact with it like any other folder on your system. For a last bit of admin work, making life easier, adding our mount to /etc/fstab so that it gets mounted automatically after a reboot. Add the following to your /etc/fstab file

bucket-name /target/folder gcsfuse rw,noauto,user,key_file=/path/keyfile.json

And thats it for today.  As usual hope this helps someone out there.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s