Building a bare-metal Kubernetes cluster on Raspberry Pi
anthonynsimon.com
anthonynsimon.com
(For the inevitable "why?": One if the quirks of this old game is you can run multiple server instances networked together to work around lack of multithreading in the code- I'm developing k8s tooling to leverage that to scale performance. https://community.bistudio.com/wiki/Arma_3:_Headless_Client)
That's not to say that running k8s on bare metal isn't something that's done. It's more difficult, because you need to do a lot of configuration and verification of best practices yourself, but it can easily become the cheaper option if you have some scaling requirements but do not require the infinite scaling possibilities of the cloud. The entire industry seems to be moving back and forth between cloud and bate metal every few years and I'm not really sure in what part of this cycle we are right now (I think more and more companies are in the process of going back to bare metal? The move in the other direction could've already started, I'm not sure.)
Technically you could set up a distributed hypervisor cluster consisting solely of networked Raspberry Pis, but I doubt you'd have many interested customers. So yes, "bare metal" is probably the norm for these computers. It's not for Kubernetes, though, and that's what makes this different from your typical deployment.
This is a tutorial on installing Ubuntu, then k3s, then other software. What exactly is "bare-metal" about this?? :)
In this context, this means running K8s nodes directly on the hardware.
As opposed to running the nodes as virtual machines. Normally VMs are used in the context of cloud providers but it's not uncommon (with beefier hardware) to run k8s as VMs in datacenters. Deployments on top of OpenStack, Azure Stack or Anthos are common. As is ESXi. It's another abstraction layer, but that gives you easier handling of things like storage and, in some cases, networking.
> More recently, the definition has confusingly expanded to sometimes include an operating system, but without a hypervisor.
That's exactly it - the definition has expanded.
In your mind, how does a computer system function without an operating system?
And that Kubernetes deployments out there primarily run on Linux.
Many do not. I've seen quite a few ARM processors running without any OS.
No, not all embedded systems run an OS. Linux is not an OS, it's a kernel. Ubuntu is an OS. Kubernetes is application software that runs on several operating systems, primarily ones based on the Linux kernel.
Ubuntu is not an OS, it's a Linux distribution.
You see this in plenty of domains: firmware, embedded systems, uEFI, bootloaders, etc.
This used to be the norm too. Old 8-bit personal computers like Commodores didn't run an OS, instead they'd have BASIC run as firmware (though you could get CP/M, GEM and others for a lot of the later generations of 8-bit micros).
You can also get modern software that runs bare metal without an OS. eg this game: https://github.com/adventurerok/Bare-metal-Space-Invaders-Cl...
I've written for bare metal on several platforms. Operating systems exist for a specific use case: when you want to run potentially multiple programs on the same piece of hardware, over time (not nec. concurrently), and you don't want your software to have to think about how to interface with the hardware. That's what operating systems do. There are plenty of cases when you don't need, or want, an OS.
Quick question, if for example you decided to another RPi to the cluster, how easy do you think it would be? Just attach it and connect to the network?
Yes, you would just attach it to the network switch and have it join the cluster.
The control plane will "discover" the additional capacity and redistribute workloads if necessary.
With k3s, a new node can join the cluster with a single command (assuming you have the API token).
Something like:
$ curl -sfL https://get.k3s.io | K3S_URL=https://$YOUR_SERVER_NODE_IP:6443 K3S_TOKEN=$YOUR_CLUSTER_TOKEN sh -I use kubespray[2] to manage my raspberry pi based k8s homelab, and replacing any nodes, including HA control plane nodes, is as easy as swapping the board and executing an ansible playbook. The downsides of this, are that it requires the users to have more knowledge about operating k8s, and a single ansible playbook run takes 30-40 minutes...
This hasn't been true for a while, since these days K3s ships with etcd embedded: https://rancher.com/docs/k3s/latest/en/installation/ha-embed...
Next on my list is set up a service mesh like istio and try inter-cluster networking between my cloud cluster and home Raspberry Pi cluster. Perhaps I can save some money on my cloud cluster by offloading non-essential services to the pi cluster.
I'm also curious about getting a couple more external SSDs and setting up some Ceph storage. Has anyone tried this? How is the performance?
One of my pain points is the interaction of the load balancer (metallb) with the router. It seems to want to assign my cluster an IP from a range, but may choose different ones at different times. Then I have to go update the port-forwarding rules on my router. What solutions do you all use for exposing Kubernetes services to the internet?
That part is incredibly annoying. Wondering about that as well. The ideal solution would involve something like a CSI driver that could talk to the router directly, as is done with cloud provider APIs.
https://metallb.universe.tf/configuration/
However now your Type: LoadBalancer won't get any ip. BUT you can now use the spec.loadBalancerIP value to manually set the ip you want.
- https://metallb.universe.tf/usage/#requesting-specific-ips
- https://kubernetes.io/docs/concepts/services-networking/serv...
Instead of MetalLB I used PureLB, but now I use no LB: https://purelb.gitlab.io/docs/
I use Rook for storage: https://rook.io/
it seems like small clusters are not economical with vanilla kube. (I say this having frequently tried and failed to do this, but not having done napkin math on system pod budgets to prove it to myself generally). and this gets worse once you try to install any kind of plugins or monitoring tools.
I really wonder if there's a hole in the market for 'manage 5-10 containers with ingress on one or two smallish nodes'. Or if there's a hard core of users of alternatives like swarm mode. this guy https://mrkaran.dev/posts/home-server-nomad/ evolved his home lab from kube to nomad to terraformed pure docker over 3 years.
I'd love to see K8s get K3s' support for using an external MySQL, Postgres, or SQLite instead of Etcd.
Why, though? The memory footprint is a couple hundred MB. You do need ideally 3 nodes but you _can_ run in one. I have deployed a single-node MicroK8s without issues.
Usually, the containers themselves (your workloads) are the hogs. Deploying multiple pod replicas in a single machine has innate inefficiencies.
also valuable for creating local copies of cloud infra so you can develop + test
There are some caveats when trying this that one should be aware of. For example there are some bugs with the iptables binary that result in megabytes of duplicate iptables rules after a few days, slowing everything down to a crawl (k3s issue 3117)
Also, lots of software on Dockerhub etc. still don't supply arm64 binaries, which means you will have to build your own containers for them if you want to use them.
Other than that, RaspberryPi 4's make excellent Kubernetes nodes (at least if you get the 8GB version, since even though k3s is reportedly a lightweight Kubernetes alternative, it still needs a couple hundred megabytes of RAM just for the k3s-server binary)
One thing that I did that might make sense for that setup was that my master has a Wi-Fi dongle and performs NAT/DHCP for the other Pis - this makes it easier to do a lot of stuff, including auto-configuration.
I'm confronted to kernel bug : https://github.com/raspberrypi/linux/issues/4490
Ideally there would be some "network-attached storage" so K8s could use PVCs transparently :)
Haven't found any non-enterprise grade solution that would do that.
Los Alamos National Laboratory put together a 750 Raspberry Pi cluster. https://web.archive.org/web/20180825200515/https://www.lanl....
If I have my story straight, it was network booted and I believe is source of another piece of software they developed, called Kraken, that helped manage the finicky-ness of a Raspberry Pi cluster. https://github.com/kraken-hpc/kraken
Kraken is a state engine. In the case of the Pi cluster Kraken provided network images, installed and configured nodes, rebooted nodes, and manipulated their state as needed to keep things running.
Another fun piece of research on Pis out of LANL is that at their altitude, 7000ft, they estimate that on average a Raspberry Pi will crash once every 2 years due to bit flips caused by cosmic rays.
There was an interesting glitch in SM64 where a player was teleported to a new location because of a specific bit being flipped by a cosmic ray. I'm curious to know how the ray flips specific bits (why certain ones and not others), and how the process works electrically.
EDIT: Ah interesting, seems like these particles are like protons coming from supernovae and black holes. They are moving basically at the speed of light, and are much smaller than the electron well where energy is stored in hardware, so that's why they are able to flip exactly one bit when they collide with that one transistor.
I’ve got a 2gb a 4gb and another 4gb lying around so if yes then might just try this