Deploying RancherOS on Vultr instances

July 15th, 2016 § 2 comments


One of things I’ve been playing with of late is a Docker container orchestration system called Rancher. I’ve been very excited to discover the features and capabilities the developers have created and despite being quite new it’s extremely well polished – for the most part it just works.

One of the projects they’d developed alongside their software is an operating system called RancherOS. It’s a light weight linux installation that runs it’s userspace entirely from within containers; the init process is docker itself. This allows the systems to run with very low overhead once booted and devote as much of their resources to the serving of your containers as is possible.

RancherOS being a relatively new kid on the block though is not available in the selection of operating systems that you can install when creating a new virtual machine on my cloud provider of choice Vultr. Fortunately for me though Vultr lets you use PXE network booting and let you add OS install options by uploading the appropriate scripts. In my searches on how to use this capability I stumbled across Vultr’s own documentation on installing RancherOS using this method. Using this I was up and running RancherOS instances within minutes and I was happy.

But soon I wasn’t quite so happy; although the PXE script got me up and running in a couple of minutes it missed out a few things that I really wanted to be automated such as the setting of my ssh key, the addition of the private network and the setting of the hostname. It was at this point I discovered that RancherOS supports cloud-init and all the goodies that provides and so I was set. I just needed a way to pull the necessary information into a cloud-init.yml file and have that read by the booting operating system. RancherOS to the rescue again as it allows you to run a script in place of a cloud-init.yml file. I was ready to go.

First up my iPXE script

# Boots RancherOS in Ramdisk with persistent storage on disk /dev/vda
# Location of Kernel/Initrd images
set base-url
kernel ${base-url}/vmlinuz rancher.state.formatzero=true \
initrd ${base-url}/initrd

You can see just how simple this is. I’m saying where the newest RancherOS is, I’m passing a couple of parameters, then I’m telling it to boot. The formatzero parameter allows me to reset a host by writing 1MB of zeros to the start of the disk and then rebooting. Upon startup the system will reinstall itself using the instructions from the cloud-init file, which I then tell it about in the datasources parameter.

The is a shell file that allows us to fetch the information we need and get installing.


V4_PRIVATE_IP=`wget -q -O -`
HOSTNAME=`wget -q -O -`

cat > "cloud-config.yaml" <<EOF
hostname: $HOSTNAME
  - ssh-rsa ...
  - path: /etc/ssh/sshd_config
    permissions: "0600"
    owner: root:root
    content: |
      AuthorizedKeysFile .ssh/authorized_keys
      ClientAliveInterval 180
      Subsystem	sftp /usr/libexec/sftp-server
      UseDNS no
      PermitRootLogin no
      ServerKeyBits 2048
      AllowGroups docker
        dhcp: true
        address: $V4_PRIVATE_IP/16
        mtu: 1450
   fstype: auto
     - /dev/vda

sudo ros install --no-reboot -f -c cloud-config.yaml -d /dev/vda
sudo reboot

This script does essentially three things. First it uses the Vultr API to pull down some information we need to setup our VM correctly. It then writes out a YML file using this information. This YML file sets my SSH key, sets up SSHD to be a little more secure, adds the private network and tell RancherOS how to go about installing itself to the virtual harddisk (/dev/vda). Finally, it tells the RancherOS system to install itself on the specified disk, using the config file just created and then reboot.

When it comes back up the system is ready to be added to the Rancher software as an available host. This isn’t currently automated but now that I think about it i’m fairly certain thats something achievable.

Tagged , , , ,

§ 2 Responses to Deploying RancherOS on Vultr instances"

  • Gerd says:

    Note: This does not work on 768MB RAM instances, they run out of memory during install!

  • Thank you for the article. I found it very enlightening as i have searched for howto articles on rancher and rancher OS. I was wondering if you have managed to install this directly to disk on Vultr and if so what steps did you utilize.
    This is the one part that i am challenged with that i believe could have been better done.

Leave a Reply

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

What's this?

You are currently reading Deploying RancherOS on Vultr instances at Real Men Wear



  • Twitter Icon Facebook Icon Delicous Icon