Setting up a development version of Rancher
After encountering a minor issue with Rancher's latest version, I decided to check if I could find more information about this problem by digging in the source code, adding some logging to the areas around the relevant parts. To start investigating this issue, I needed a testing environment that hopefully also shows this issue.
First, we need a machine to build and run Rancher. You can use a VirtualBox VM or some VPS online installed with Ubuntu 20.04.
There are a few prerequisites before you're able to build Rancher. For one, we need to install Docker, and we can do so by using Rancher's docker install script or any other way you'd prefer.
Once that's installed, we'll need to set up a Kubernetes cluster. To make it easy, we'll use Rancher's lightweight Kubernetes distribution called K3s. We're using the docker engine to enable the use of docker images. K3s uses CRI-O by default, which doesn't use the images loaded into Docker by the build process later on.
Once it's up and running showing a "Ready" node, we should install Kubectl for convenience.
Once that's up and running, let's install HELM to deploy the Rancher generated HELM package once we've created our develop build. We're living on the edge, so this will be easy.
We'll also need to use Docker directly. If you are using a regular user, you'll have to allow access to Docker by adding the user to the "docker" group.
Now we've set that up, we need to grab the source code and build it. We start by cloning the Rancher source code from their GitHub.
After we've cloned the source code, we can jump into building it. First, we'll remove the test step from the ci scripts; making Rancher build a lot quicker. You can also temporarily remove the validate step if you want it to be even quicker.
The new ci script looks like this for me.
We need to commit the change to the ci script and run "make". If you do not commit the change to git, the build process will tell you the repository is dirty.
Running the make command may take a long time, depending on the system resources you've given the VM. The first build took me about 30 minutes. Once the building process finishes, you'll see docker images with the same tag as "VERSION" in the local registry.
The build process will automatically generate a HELM chart to deploy your development build version of Rancher. Let's deploy Rancher!
First, we need to install a cert-manager to let Rancher deal with the certificates.
Once that is installed, let's install Rancher itself.
Let's check if Rancher can start.
Let's open up the domain given to HELM in a browser.
That worked! Now we can log in using the password given to HELM.
Once logged in, we can see our development version of Rancher running by checking the hamburger menu on the left top side.
Lets's set up Virtual Studio Code (vscode for short).
First, we need to install vscode. Which should be pretty straightforward.
Next, we should install some extensions. The following will be needed:
Next we'
From now on, you can change whatever you need to the code, commit, build, helm upgrade and test.
I hope I find this blog post very interesting when I refresh my memory. To everyone else who reads this, thank you!
Additional information:
Don't forget to up the log level
kubectl -n cattle-system get pods -l app=rancher --no-headers -o custom-columns=name:.metadata.name | while read rancherpod; do kubectl -n cattle-system exec $rancherpod -c rancher -- loglevel --set debug; done