Containers / Edge / IoT / Kubernetes

Automate K3s Cluster Installation on Flatcar Container Linux

3 Feb 2021 3:00am, by

This tutorial is the fourth and the last part of a series on running Flatcar Container Linux. (Part 1), (Part 2). (Part 3). 

In this tutorial, we install a highly available K3s cluster along with Flatcar Container Linux. K3s is a stripped-down Kubernetes distribution designed for edge computing deployments.

To complete this tutorial, you need to be familiar with the installation process of putting Flatcar Linux on remote bare metal servers. We extend the scenario to automate the installation of K3s along with the OS.

Leveraging Ignition to Configure K3s Installation

Let’s do a quick recap of the bare metal installation process of Flatcar Container Linux.

We take the help of two Ignition files to configure the OS. Ignition is a provisioning utility designed specifically for container OSs like Flatcar Container. The first file runs during the PXE boot installation process that ends by downloading and persisting the second Ignition file to the disk.

The persisted Ignition file, node-1-ignite-boot.ign stored as /opt/ignition.yaml is used during the boot time to configure the OS. It configures users, hostname, NTP servers, and other settings.

We can also include systemd unit files in this file that may run during the boot process. We will leverage this to install K3s.

Installing K3s Server on the First Node

The typical installation of K3s includes running the below command which first downloads a script and then pipes the output to the shell.

We will turn this step into a systemd unit file that will run at the boot time. To avoid reinstalling K3s, we will check the presence of /opt/bin/k3s, and skip the process if it’s available.

On the gateway server, modify the node-1-ignite-boot.yaml file to add K3s installation process.

First, we download the K3s installation script from https://get.k3s.io and save it to /opt/k3s-install.sh.

The below snippet under the storage section will perform this step.

We then create a systemd unit file that executes after the network service is started. It checks for /opt/bin/k3s file and runs the downloaded installation script only if the file is not found.

Note that we are passing the parameters expected by the K3s script through the environment variables.

Convert the YAML file to JSON by running the configuration transpiler.

Continue with the rest of the PXE boot process to install Flatcar Linux followed by K3s.

Automating K3s Server Installation on Remaining Nodes

The entire installation process remains the same except for generating the boot time Ignition files.

We will need to include the K3s configuration for joining the nodes to the first server.

The below Ignition file is used for configuring the second node:

Notice the environment variables used for configuring the K3s node.

Except for the hostname, the same configuration is applicable to the third node of the cluster.

Finalizing and Verifying the Configuration

At this point, you should have 6 Ignition files in the /var/lib/tftp/ignition – three files PXE booting each node and three files for configuring and installing K3s on each node.

In the /var/lib/tftp/pxelinux.cfg directory, make sure that you have the three PXE boot files for each node and a link mapped to the IP address of the nodes. Refer to the previous part of this tutorial for the details on this topic.

Ensure that the PXE boot server is running, and reboot the nodes. Within a few minutes, you will have a fully configured, highly available K3s cluster deployed on bare metal servers running Flatcar Container Linux.

Janakiram MSV’s Webinar series, “Machine Intelligence and Modern Infrastructure (MI2)” offers informative and insightful sessions covering cutting-edge technologies. Sign up for the upcoming MI2 webinar at http://mi2.live.

Feature image by Pascal van de Vendel on Unsplash.

A newsletter digest of the week’s most important stories & analyses.