Setting up a Kubernetes lab with Rancher — Part 1 Setting up the Host

Fusion
6 min readApr 4, 2019

--

Rancher is a software stack that manages Kubernetes. Over the past year, I have dived deeper in running and creating docker images. I wanted to dive deeper and find a way to manage all my containers. Rancher does a great job of this and has built-in monitoring.

This guide will walk through setting up Rancher, creating nodes, and launching your first application. To help keep this guide organized and focused, it will be in three parts.

While this Rancher deployment is being set up in a home lab, I plan on using it for personal use and will be planning this build accordingly.

At the end of this guide, you will have a;

Rancher Host — Kubernetes Master Host

etcd node — used as a datestore for Rancher

Controller-Plane Node — used to control the cluster

Worker Node — used to run the containers

It is best practice to not run multiple roles on nodes, so I am keeping them separate.

Requirements:

Linux OS — You can use Ubuntu\RHEL\CentOS or RancherOS. In this guide, we will be using RancherOS. Fair warning if you use Ubuntu; Ubuntu now uses systemd instead of dnsmasq and will cause issues.

Download RancherOS here, https://rancher.com/rancher-os/

4 Virtual Machines (Host, Controller, etcd, and Worker nodes)

I’m creating my nodes with 4 CPUs, 8GB RAM, and 20GB Hard Drive Space. If you are doing just a lab, you can do 1 CPU, 4GB RAM and 10GB Hard Drive Space.

Putty and PuttyGen (or a way to create ssh rsa keys)

Basic understanding of Docker, Linux, and Networking

Let’s get started;

Preparing the Host

This will walk you through,

  1. Booting up the VM with RancherOS
  2. Changing the user “rancher” password
  3. Use Putty to SSH to the host
  4. Generate SSH Key
  5. Creating a cloud-config.yaml
  6. Installing RancherOS to disk

Boot up your VM with the RancherOS ISO attached

When the OS is loaded, it will look like this,

The first step is to change the rancher user password so we can log into it via SSH. This password will not be saved. This is a step that will grant temporary access.

In the console, type

sudo /bin/bash

and then,

passwd rancher

Type in the password you want to use to login via SSH, and then type exit to leave the root shell.

Generate SSH Keys

Launch PuttyGen to generate the SSH Key and click on “Generate”,

Move your mouse around on the screen to generate the key. You can add a key passphrase if you want to enhance the security of your key even more.

Once that is done, click on both “Save public key” and “Save private key”

Creating Cloud Config

Now, open Putty and SSH into the machine using the rancher user and the password you set for temporary access, not the ssh key we just generated.

Now type,

vi cloud-config.yaml

Copy and paste the below template into vi and change the following to match your needs.

hostname — type in the name your want to name your rancherhost

address — set a static IP for this host

nameservers — you can use your internal DNS or external DNS.

ssh_authorized_keys — copy and paste your public key

#cloud-config

hostname: hostname

rancher:
network:
interfaces:
eth*:
dhcp: false
eth0:
address: 192.168.2.10/24
gateway: 192.168.2.1
dns:
nameservers:
- 192.168.2.1

ssh_authorized_keys:
- ssh-rsa PASTEKEYHERE

It should look like this inside of vi.

Now, hit the esc button and type :wq then enter to write and quit vi

Installing RancherOS

Validate the config,

sudo ros config validate -i cloud-config.yaml

If it doesn’t report any errors, proceed to the next step. If there are errors, check for tabs as that will break a yaml file.

Installing RancherOS to disk,

Type in,

sudo ros install -c cloud-config.yaml -d /dev/sda

and choose yes when prompted,

The install only takes a couple of seconds to complete. After the install is finished, choose yes to reboot,

When it boots back up, you can view through the VM console and see if the IP you set matches the current IP. If it does, the install went as planned.

Now, SSH into the host using the private key file you made and the IP address of the host.

Open Putty, type in the IP of your host in the Host Name field, then on the side go to Connection/SSH/Auth and click on browse. Choose the private key you made and click on Open.

Login as user “rancher” and type in your passphrase if you used one.

You are now connected via SSH to your Rancher Host

Creating the Host

The next step is to install the actual host.

Run this command,

sudo docker run -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher

As you can see, the host is installing,

Then it is finished,

After the setup is complete, open your web browser and go to the IP of the rancher host. This is the IP you added to your cloud-config.

Setting up the Rancher UI

You will be prompted to change the password for the admin user,

After that, you will be prompted to enter a hostname or IP. Enter the IP of the server or create a DNS record on your DNS server with the hostname you choose in the cloud-config file pointing to the IP of your host.

Congrats! You have now installed the host for Rancher.

The next steps will be to setup a cluster add nodes, which will be in Part 2 of this guide. I hope you have enjoyed setting this up!

Click here for Part Two!

--

--