Tutorial : Setup RancherOS - Baremetal - Hetzner

Setup of an RancherOs Server using RancherOS iso on Hetzner dedicated server provider


This document will not talk about setting an Rancher Platform or building cloud-config.yml file or joining a rancher-kubernetes cluster.
You need to speak a bit of Linux tools to be able to handle this properly.

Preparations

  1. Order your server
  2. Ask for a KVM connection with an usb-key with the latest version of RancherOS
  3. Boot directly on the key using bios features
  4. You are now on a running live-iso Rancher that you are gonna use to setup the server properly
  5. Run the command sudo passwd rancher then enter a dumb password to be able to acces to your server through SSH with password authentication
  6. Run the command sudo ros console switch debian to swith to a debian console with apt commands
  7. Run again the ‘5’ command to be able to reconnect by SSH as the system console has been destroyed by the ‘6’
  8. You are now connected with SSH on a debian-like console
  9. Run the command sudo apt-get update; sudo apt-get install mdadm -y to have the minimum required tools available
  10. You can run all the commands with sudo or directly as root (your choices)

Disks - Raid - Filesystems - Label

Depending on the type of server that you are using but on this case we have 2*1.8TB of disk and 2*256GB of SSD.
We are going to use 4 partitions on the 1.8TB disk for the system and local storage that we will use the ssd as another storage for high I/O operations.

Partitions

My 1.8TB disk are available on the server as /dev/sdc and /dev/sdd wich mean that the SSD disks are available as /dev/sda and /dev/sdb.
I’m creating the partition on the 1.8TB with the fdisk utility with a dos partition table not a GPT ! (Important)
Name of the partitions doesn’t really matters at this moment as it’s just a guide for the next steps.

Device Name Size Id Type Boot Flag
/dev/sdc1 RANCHER_BOOT 500M 83 Linux Yes
/dev/sdc2 RANCHER_SWAP 2G fd Linux raid autodetect No
/dev/sdc3 RANCHER_OEM 5G 83 Linux No
/dev/sdc4 RANCHER_STATE 1.8T 83 Linux No

I’m duplicating theses partition table to the other disk of 1.8TB with the following commands :
sfdisk --dump /dev/sdc | sfdisk --no-reread /dev/sdd

For the SSD disks i’m creating only one partition using the full disk capacity

Device Name Size Id Type Boot Flag
/dev/sda1 RANCHER_SSD 238.5G 83 Linux No

I’m duplicating theses partition table to the other disk of 1.8TB with the following commands :

sfdisk --dump /dev/sda | sfdisk --no-reread /dev/sdb

Raid-Array

Now that ours disks are ready we can now build our Software Raid arrays:

mdadm --create /dev/md1 --level=1 --metadata=1.0 --raid-devices=2 /dev/sdc1 /dev/sdd1
mdadm --create /dev/md2 --level=1 --metadata=1.2 --raid-devices=2 /dev/sdc2 /dev/sdd2
mdadm --create /dev/md3 --level=1 --metadata=1.2 --raid-devices=2 /dev/sdc3 /dev/sdd3
mdadm --create /dev/md4 --level=1 --metadata=1.2 --raid-devices=2 /dev/sdc4 /dev/sdd4
mdadm --create /dev/md5 --level=1 --metadata=1.2 --raid-devices=2 /dev/sda1 /dev/sdb1

You can monitor the status of the raids by looking on this file :

cat /proc/mdstat


Personalities : [raid1] 
md5 : active raid1 sdb1[1] sda1[0]
      249926976 blocks super 1.2 [2/2] [UU]
      bitmap: 0/2 pages [0KB], 65536KB chunk

md124 : active raid1 sdc1[0] sdd1[1]
      511936 blocks super 1.0 [2/2] [UU]
      	resync=DELAYED
      
md125 : active raid1 sdc2[0] sdd2[1]
      2095104 blocks super 1.2 [2/2] [UU]
      
md126 : active raid1 sdc3[0] sdd3[1]
      5238784 blocks super 1.2 [2/2] [UU]
      
md127 : active raid1 sdc4[0] sdd4[1]
      1945530432 blocks super 1.2 [2/2] [UU]
      [===============>.....]  resync = 76.1% (1481158464/1945530432) finish=77.5min speed=99784K/sec
      bitmap: 6/15 pages [24KB], 65536KB chunk

unused devices: <none>

The resync progress bar is about the state of sync between the 1.8TB disks, you can imagine that it’s not an easys steps for theses disks to be on sync. I recommand to wait the complete sync of the array before moving to production.

Filesystems

Now that we have our disks (raid-array) ready we can go on creating filesystem

mkswap -L RANCHER_SWAP /dev/md2
mkfs.ext4 -L RANCHER_BOOT /dev/md1
mkfs.ext4 -L RANCHER_OEM /dev/md3
mkfs.ext4 -L RANCHER_STATE /dev/md4
mkfs.ext4 -L RANCHER_SSD /dev/md5

Setup

At this point, you have your disks, raid array and filesystems correctly setup the only stuff to do now is to install RancherOS using your cloud-config.yml file:
ros install -t noformat -a rancher.state.mdadm_scan -d /dev/md4 -c cloud-config.yml

The -t tell rancherOS to not format the partition as we have already done it.
the -a tell rancherOS to add a kernel instructions on the bootloader to look after raid-array
The -d tell rancherOS where to install the OS.
the -c is the location of the cloud-config.yml file which could be locally on the server or using an URL.

Congrats, you should have a running RancherOS server available throught SSH worldwide (with the appropriate authentication setup). !!!

Extra Steps - SSD Mountpoints

Depends on your server hardware and options

We didn’t use the RANCHER_SSD raid array as this point as we are going to instruct RancherOS to mount it automaticly. At the time of his creation ( on the RancherOS iso) it was named /dev/md5 but now on the living RancherOS his named /dev/md124.
In order to do that prepare a file like this one ex: cloud-mount.yml

#cloud-config
mounts:
- ["/dev/md124", "/ssd-storage", "ext4", ""]

Then run the following command :
ros config merge -i cloud-cmd.yml

This will add the mount instructions to the config of RancherOS and at the next reboot we should have the ssd-raid-array available at the /ssd-storage location which can be use as storage on the Kubernetes level.

The default location of the RancherOS configuration is :
/var/lib/rancher/conf/cloud-config.yml

Extra Steps- Optionnal - Swap activation

In order to have some swap available for the system you can use the following file (cloud-cmd.yml):

#cloud-config
runcmd:
- swapon -L RANCHER_SWAP

Then run the following command :
ros config merge -i cloud-cmd.yml

This will add an extra instruction during the boot process to enable the swap using the partition labeled as RANCHER_SWAP.

Enabling swap on systems running docker can be problematic on some workflows.

Author Notes

I just did a big mashup of all the sources. Please free to add some comments in order to help other to achive theirs goals in using RancherOS. I’ve been using the Ubuntu as the base OS but i consider RancherOS to be a nice choices in order to reduce the load on maintaining an OS and an Rancher setup with all the things that could happens on boths areas.
The main avantages for me is the low needs of ressources in order to be running and an easy command line and syntax.

Bibliography-Sources

RancherOS-Documentation - Custom Layout Partition
RancherOS-Documentation - Configuration
Medium Article - Rancher OS & Raid - Simon Thulbourn
Gist from Kimmo Lankila (krisnod)
Software Raid

I get the following error:


How can I solve this? Thanks!

Hello,

You have the root cause directly on your output.
You didn’t provide the cloud-config.yml with the -c option on the ros install command.

Check again the links on the biblio about the Configuration of RancherOS.