/balenaRancher

Create a Raspberry Pi4 based kubernetes cluster with Rancher and k3s, in a balenaCloud fleet!

Primary LanguagePython

rancher steer balenaRancher

### Updated ###

AMD64 Supported!!! You can now add Intel-Nuc and generic AMD64 based "Ranch Hands" to your k3s cluster. Due to limitations in Balena Fleet configurations you will need to have a seperate fleet to contain your AMD64 devices. But it is easy to copy over the proper variables to have them automatically join your existing Raspberry Pi Rancher cluster. I have tested this extensivly with Libvirt/QEMU virtual devices and it works very well. You can run ARM64 or AMD64 based images in the same cluster.

The configuration method has also been updated! Now you just need to get an API Key from the balenaCloud console and add it as a Fleet Variable. When the Rancher server starts up it will create the required K3S_TOKEN and K3S_URL Fleet Variables for you!


Use balenaRancher to easily deploy a Raspberry Pi4 based kubernetes cluster with a Rancher server and k3s worker nodes. The deployment is slightly more complex than your typical BalenaCloud deployment... but this is kubernetes, so it's never 'easy'!

Equipment / Software needed

  • 1 or more Raspberry Pi 4s (4/8 GB model for the Rancher server, 1/2/4/8 GB model for worker nodes)
  • This repo cloned to a directory of your choosing
  • Balena-cli installed

Install / Config / Deploy

BalenaCloud setup

This project assumes a fairly advanced level of knowledge about BalenaCloud and the steps to create a new fleet. If this is your first time deploying a project, we recommend familiarizing yourself with BalenaCloud by following the steps in this Getting started tutorial and then coming back here to deploy your Rancher server and ranch-hand worker nodes.

  1. Create a new fleet in balenaCloud and name it balenaRancher.
  2. Go to access-tokens and click on the Create API key button to create an API key. Copy this key somewhere safe before moving to the next step. We are going to need the key and it is only displayed once. If you messed up and didn't copy it, make a new one.
  3. Click on the name of your fleet (balenaRancher) in the side-bar and then click on Variables. We are going to create a Fleet Variable for your API Key
  4. Click the Add variable button and create a variable with the name API_KEY and paste the api key that you copied in step 2, to the value
  5. Add a device to your new fleet.

balenaRancher setup

these are the barebones instructions to get you started... better instructions are planned

Rancher Server

IMPORTANT: Make sure that you have your API_KEY fleet variable set, before provisioning your server... nothing will work correctly if you don't have the API_KEY.

  1. Clone this repo git clone https://github.com/SamEureka/balenaRancher.git
  2. Change to the balenaRancher directory cd balenaRancher
  3. Push a draft release to your fleet balena push balenaRancher --release-tag rancher-server --draft using --release-tag will help you identify the correct release to 'pin' and --draft will prevent the releases from automatically deploying to your devices.
  4. Log into your balenaCloud console and find the device that you want to use as the rancher server. Using these steps pin the server device to the release tagged with rancher-server
  5. Once the rancher server release has deployed and your rancher server is up and running. Open the Rancher UI in a browser using the local ip address. The default login is admin / b@13n4!

Ranch-Hand worker node setup

  1. Add another device to your balenaRancher fleet
  2. In the balenaRancher repo, change directory to the ranch-hand directory cd ranch-hand
  3. Use the balena-cli to push a release for your worker-nodes. In this example the fleet is called balenaRancher. balena push balenaRancher --release-tag ranch-hand --draft again, it is important to use the --release-tag and --draft flags to make sure that you can identify the correct release and prevent the ranch-hand release from automatically installing to your server.
  4. Log into balenaCloud console and find the device you want to use for your worker node. Pin the device to the release tagged ranch-hand (pinning device to release)
  5. When the ranch-hand node is done initiallizing, you should see an additional node in the Rancher server UI.
  6. You can additional nodes by provisioning a device and pinning the 'ranch-hand' release to the device. It will automatically join the rancher cluster.

AMD64 Ranch-Hand worker node setup

IMPORTANT AMD64 devices CANNOT be in the same fleet with ARM64 devices. You will need to create a new fleet to contain the AMD64 based Ranch Hands. I named mine balenaRancherAMD and the instructions below use the same name.

  1. Add a device to your balenaRancherAMD fleet. You will want to select Intel-Nuc or Genericx86-64-ext as the device type.
  2. Copy the API_KEY, K3S_TOKEN, and K3S_URL variables from your balenaRancher fleet.
  3. In the balenaRancher repo, change directory to the ranch-hand-amd64 directory cd ranch-hand-amd64
  4. Use the balena-cli to push a release for your worker-nodes. In this example the fleet is called balenaRancherAMD. balena push balenaRancherAMD --release-tag ranch-hand-amd64 --draft again, it is important to use the --release-tag and --draft flags to make sure that you can identify the correct release and prevent the ranch-hand-amd64 release from automatically installing to your server.
  5. Log into balenaCloud console and find the device you want to use for your worker node. Pin the device to the release tagged ranch-hand-amd64 (pinning device to release)
  6. When the ranch-hand-amd64 node is done initiallizing, you should see an additional node in the Rancher server UI.
  7. You can additional nodes by provisioning a device and pinning the 'ranch-hand-amd64' release to the device. It will automatically join the rancher cluster.

Note:

When the worker nodes (ranch-hands) reboot, they don't always re-join the cluster correctly. You may have to delete duplicate nodes in the Rancher UI. This isn't a desired behavior and I'm working on fixing it. Fixed

Environment Variables

Name Value
API_KEY Generate a key by going to access-tokens and clicking on the Create API key button
K3S_TOKEN output of the command cat /var/lib/rancher/k3s/server/node-token executed on the rancher server
K3S_URL Url that the worker node uses to connect to the Rancher server. https://<rancher server ip>:6443
CATTLE_BOOTSTRAP_PASSWORD Creates the default password for the admin account in the Rancher UI. Default value is b@13n4!