Wojtek @suda Siudzinski


ObjC/Python/Node developer, DIY hacker, rookie designer, 3D print junkie. CEO @ Gaia Green Tech, Senior Full Stack @ Particle.io


5-minute home server with microk8s and Rancher

After getting tired with instability of my QNAP TS-251B (random reboots once a day, official apps not working) I decided to turn my Intel NUC into a home server. I could've used a Raspberry Pi, but I do need a x86 for most of the Docker images I use. I decided to use Kubernetes, which for many might come off as a huge overkill (and possibly it is) but that's what I'm interacting with in my professional life thus it's easier for me to do what I need in a familiar environment :)

I looked through single node Kubernetes installation options, I found microk8s which Kelsey Hightower called "the easiest way to provision a single node Kubernetes cluster". Oh boy was he right! Ubuntu Server comes with an option to install microk8s making it practically zero effort installation!

Second part for me was to add some GUI to manage. I choose Rancher as it has a great integration with both Kubernetes and kops.

Installation

First start with a fresh installation of Ubuntu Server. I used 18.04 LTS but feel free to use latest version. To make a bootable USB drive with the image, you can use Balena Etcher. Once you have it installed on your machine, ssh into it and issue following commands:

# Install microk8s from the edge channel (Rancher requires Helm 2.15.1 or above)
$ sudo snap install microk8s --classic --edge
# Enable useful plugins
$ sudo microk8s.enable dns dashboard storage ingress helm

# Allow running priviledged Pods (required by Rancher's `cattle-node-agent`)
$ sudo sh -c 'echo "--allow-privileged=true" >> /var/snap/microk8s/current/args/kube-apiserver'
$ sudo systemctl restart snap.microk8s.daemon-apiserver.service

# Setup and install Tiller (part of Helm)
$ sudo microk8s.kubectl create serviceaccount tiller --namespace kube-system
$ sudo microk8s.kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
$ sudo microk8s.helm init --service-account=tiller

# Install cert-manager user by Rancher
$ sudo microk8s.helm repo add jetstack https://charts.jetstack.io
$ sudo microk8s.kubectl apply -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.9/deploy/manifests/00-crds.yaml
$ sudo microk8s.kubectl create namespace cert-manager
$ sudo microk8s.kubectl label namespace cert-manager certmanager.k8s.io/disable-validation=true
$ sudo microk8s.helm install --name cert-manager --namespace cert-manager --version v0.9.1 jetstack/cert-manager

# Install stable Rancher
$ sudo microk8s.helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
$ sudo microk8s.helm install rancher-stable/rancher --name rancher --namespace cattle-system  --set replicas=1 --set hostname=${HOSTNAME}.home

Now you should be able to see Rancher interface at https://SERVER_IP! There are two manual tasks you need to do on your machine:

  • the SSL certificate will be marked as invalid so you'll need to add it to trusted certificates
  • Rancher is installed with a ${HOSTNAME}.home hostname which you need to add to your /etc/hosts file (.local domain can't be used with Rancher)

Hope this worked and let me know if you have any comments!

P.S: If you're using Raspberry Pi, the Rancher folk created k3s which is a single node Kubernetes installation that requires <512MB of RAM!

comments powered by Disqus