Livin’ Kubernetes on the (Immutable) Edge with Kairos Project
A new open source project is designed to tackle the need for immutability and atomic upgrades.
Dec 1st, 2022 11:05am by
Image of Aerosmith from YouTube.
Spectro Cloud sponsored this post.
Immutability Is the Next Step Beyond Configuration Management
An immutable OS is a carefully engineered system that boots in a restricted, permissionless mode where certain paths of the system are not writable. For instance, after installation it’s not possible to install additional packages in the system, and any configuration change is discarded after reboot. This reduces a malicious attacker’s surface, which is vitally important at the edge, where devices may be physically available for tampering. At the same time, it makes sure every node runs a certain version of the software stack, reducing the risk of infrastructure drift.Immutability: One Distribution at a Time
This is where Kairos comes in. Kairos is a new open source project designed to tackle the need for immutability and atomic upgrades. In that sense it’s like Talos, FlatCar and K3OS, which we discussed above. But there are very important differences: Kairos is distribution-agnostic, Open Container Initiative (OCI)- based and cloud-init first. Let’s take a look at what this means Distribution agnostic: Unlike, say, K3OS, Kairos is not a Linux distribution. It’s a meta-Linux distribution, which means it enables you to spin up an immutable Kubernetes cluster with the Linux distro of your choice. Kairos is distribution-agnostic by design and supports converting existing distributions from container images to “Kairos-based” distributions. Those automatically inherit features such as A/B atomic upgrades, immutability, live layering and all the Kairos featureset. Importantly, the kernel and initramfs are static and shipped with the image, which really means atomic upgrades for the entire full stack of the system. At the time of writing this article, Kairos is at 1.3 and supports openSUSE-, Alpine- and Ubuntu-based distributions, which can be directly downloaded from the released assets and will be used in the examples below. OCI-based: OCI-based means Kairos uses container images. The OS itself is just a single image container that runs natively on the host without any container engine, and it’s overlayed in the booting system with overlayFS. Upgrades are handled atomically with an A/B schema and automatic fallback. Because Kairos is just an OCI image, you can find the container image in the quay repositories, which can be used to burn ISOs to USB sticks or other media. ISOs are available as well as part of the releases, so we don’t have to worry about that and we can pick the distribution we like among the published assets. Cloud-init first: The only configuration mechanism for Kairos is performed via cloud-init. As a single source of truth, it is used to configure one or all your nodes in the cluster. This is to enhance user maintenance and configuration at scale, reducing the impact of complex configuration infrastructure required to manage nodes. Management is optionally handed over to specific Kubernetes components that manage the life cycle of the nodes after bootstrap.Hands-On with Kairos
Let’s have a closer look at Kairos, and use it to deploy a K3s cluster with MetalLB. In the example below I’m going to use a bare metal host to provision a Kairos node in my local network with K3s and deploy Kubedoom, but similarly you can provision nodes with a VM by following the official quickstart with different charts, manifests and setup.Step 1: Download a Release and Flash It to a USB Stick
As Kairos comes with different flavors, we can pick between the base distribution of our choice and the version of K3s. Kairos publishes artifacts with K3s included in the image in a separate repository including the release artifacts. This is because it is possible to install additional extensions at runtime. But in this case we want K3s, so we just use the images with K3s inside. We are going to need a .ISO file, as we will flash it to an USB stick in case of a bare metal boot; otherwise we would just load it in the hypervisor settings. In this article we will use the openSUSE image, and we will pick the latest K3s available version. Kairos has recently added support for Ubuntu and Fedora, and other distributions are available as well, but the openSUSE flavor is well tested and available since the early releases. We are going to use now a machine to flash the image to a USB stick:
```
wget https://github.com/kairos-io/provider-kairos/releases/download/v1.3.0/kairos-opensuse-v1.3.0-k3sv1.23.14+k3s1.iso
```
```
dd if=kairos-opensuse-v1.3.0-k3sv1.23.14+k3s1.iso of=/dev/sda oflag=sync status=progress
```
Step 2: Install and Boot the Node
Now we can use the USB stick as a Kairos installer. If it were a VM, we could have just loaded the ISO. A Kairos node needs a configuration, and in this article we are going to install MetalLB and Kubedoom, so it will look similar to https://gist.github.com/mudler/bde499f156513bbfe2030587295adfca:
#cloud-config
hostname: kubedoom-{{ trunc 4 .MachineID }}
users:
- name: kairos
# Change to your pass here
passwd: kairos
ssh_authorized_keys:
# Add your github user here!
- github:mudler
k3s:
enabled: true
args:
- --disable=traefik,servicelb
# Additional manifests that are applied by k3s on boot
write_files:
- path: /var/lib/rancher/k3s/server/manifests/metallb.yaml
permissions: "0644"
content: |
apiVersion: v1
kind: Namespace
metadata:
name: metallb-system
---
apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
name: metallb
namespace: metallb-system
spec:
chart: https://github.com/metallb/metallb/releases/download/metallb-chart-0.13.7/metallb-0.13.7.tgz
- path: /var/lib/rancher/k3s/server/manifests/kubedoom.yaml
permissions: "0644"
content: |
apiVersion: v1
kind: Namespace
metadata:
name: kubedoom
---
apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
name: kubedoom
namespace: kubedoom
spec:
chart: https://github.com/spectrocloud-labs/kubedoom-chart/releases/download/kubedoom-helmchart-0.0.1/kubedoom-helmchart-0.0.1.tgz
set:
kubedoom_namespace: "kube-system"
- path: /var/lib/rancher/k3s/server/manifests/addresspool.yaml
permissions: "0644"
content: |
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: default
namespace: metallb-system
spec:
addresses:
- 192.168.1.10-192.168.1.20
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: default
namespace: metallb-system
spec:
ipAddressPools:
- default
- We disable Traefik and the default load balancer that comes with K3s to use MetalLB instead. An
IPAddressPoolis configured to use the IPs, and anL2Advertisementis associated with it. - Be sure to replace
192.168.1.10-192.168.1.20in theIPAddressPoolwith the available IP range in your network. The service will automatically take one of the IPs in the range, and we will use that to connect to Kubedoom afterward. - Replace also the GitHub username (`github:mudler`) with yours to automatically login via SSH using your keys (this works only if you have uploaded your SSH public keys to GitHub). If you don’t have any, we have also set `kairos/kairos` as username and password so you can also log in with a password prompt.
- If running in a VM, the network interface needs to be bridged to your local network in order to correctly connect to Kubedoom.
- Check out the documentation for more information on the available fields in the configuration file if you need to add any other setting or additional user logic.
```
scp config.yaml kairos@<IP>:./
ssh kairos@<IP>
sudo kairos-agent manual-install --reboot --device auto config.yaml
```
Step 3: Log in and Check if You Can Run Your Workload
After the installation has ended, the node will reboot. The first boot might take some time to spin off the cluster, but eventually we should be able to login via SSH with kairos/kairos and via the console as well:
```
ssh kairos@<IP>
```
```
sudo systemctl status k3s
sudo k3s kubectl get nodes -A
```
```
testcluster-3646:~ # kubectl get svc -o wide -n kubedoom
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
kubedoom-kubedoom-helmchart-kubedoom ClusterIP 10.43.152.192 <none> 5900/TCP 68m app=kubedoom
kubedoom-kubedoom-helmchart-novnc LoadBalancer 10.43.46.202 192.168.1.10 6080:30966/TCP 68m app=novnc
```
Cheat codes for Kubedoom and instructions are available here. 🙂
To upgrade the node and manage it after installation, we can either do that manually or with Kubernetes. All the details are in the Kairos docs.
Conclusion: What We Need for Life at the Edge
From the easy abstraction of the cloud, we are transitioning to the tangible hard reality of bare metal at the edge. No one can pretend to know what every edge scenario demands, so an ideal OS needs to be flexible enough to take into account any customization to the stack and make changes and upgrades easy, with the same confidence we have when deploying applications to Kubernetes. This is crucial, as it helps scaling out with the same framework among various use cases that can arise while provisioning nodes to the edge. When it comes to what OS to install on a cluster, we have to take into account how the nodes will upgrade, what are the fallback systems in place and whether we can handle the automation in a familiar fashion. In the cloud native era that means managing Kubernetes in Kubernetes! This is why immutable OSes are getting really popular — they are a perfect fit for running Kubernetes workloads, as they are static OSes that run and upgrade (usually) atomically. In this article we’ve analyzed the aspects that make immutability important for adopters, especially for the compelling properties that immutable infrastructures can bring at the edge. Kairos’s cloud-centric, container-based approach brings version control of the OS at the edge with single, atomic upgrades that can be rolled over to the cluster nodes similarly to application upgrades with the Linux distribution of your choice. As Aerosmith sang, Tell me what you think about your situation Complication, aggravation Is getting to you, yeah With a tool like Kairos, our goal is to make livin’ on the edge less complicated, less aggravating, with the power of immutability. You can find out more about Kairos and get started at kairos.io. We welcome any feedback and contributions 🤗!
YOUTUBE.COM/THENEWSTACK
Tech moves fast, don't miss an episode. Subscribe to our YouTube
channel to stream all our podcasts, interviews, demos, and more.