How to get your Kubernetes cluster for Runtime Fabric in 2 mins!

K3s is a simple and lightweight Kubernetes distribution. It is designed to be easy to install, run, and manage. In our last post, we saw in detail the main features and use cases of K3s. For us, Mulesoft Architects and Developers, K3s can be a great way for us to get a Runtime Fabric instance for dev or testing. This way we don't have to go through all the installation process of an EKS, AKS or Openshift cluster and the installation and configuration of an ingress controller.

In this post, we are going to see how easy and quick is to install a K3s cluster and get it ready to get Runtime Fabric installed.


Installing K3s

System Requirements

  • Minimum 512 MB RAM (recommended 1 GB)
  • Minimum 1 CPU (recommended 2)
  • SSD disk recommended
  • Operating System - K3s is supported by most of the Linux distros (CentOS, Red Hat Enterprise Linux, Debian/Ubuntu, SUSE/OpenSUSE and also Raspberry Pi OS (Debian based)
  • Ports
    • Kube API Server - 6443 via TCP
    • Flannel VXLAN - all server and agent nodes need to be able to communicate with each other over port 8472 via UDP
    • Metrics Server - 10250 via TCP
  • For the full and detailed list of requirements check out the official K3s docs

Installation script

Installing K3s is super easy. You only need to run one script provided by K3s. The script is located at https://get.k3s.io. Download the script and run it, that's it!

You can do all at once from your terminal with this command:

curl -sfL https://get.k3s.io | sh -

For a standard installation that's all you need - one command. How cool is that?

If you need to customize the installation you can use environment variables. For example, you could use the following env variables:
  • INSTALL_K3S_VERSION - Specifies the version of Kubernetes we want to install. 
  • INSTALL_K3S_BIN_DIR - Specifies the directory for installation.
  • INSTALL_K3S_EXEC - Command with flags to use for launching K3s in the service. Passes additional arguments to the k3s server or k3s agent command. Some examples:
    • INSTALL_K3S_EXEC="--write-kubeconfig-mode 644" this sets the file mode for the kubeconfig file.
    • INSTALL_K3S_EXEC="--tls-san <string>" - Adds additional hostname or IP as a Subject Alternative Name in the TLS certificate used by the K8s API Server. Example: --tls-san="example.com".
    • INSTALL_K3S_EXEC="--disable <string>" - Disable specific built-in components. We can use it to disable Traefik if we want to use a different ingress controller with the flag --disable=traefik.
    • INSTALL_K3S_EXEC="--cluster-cidr <cidr>" - Network CIDR to use for pod IP addresses. Example: --cluster-cidr="10.42.0.0/16"
    • INSTALL_K3S_EXEC="--service-cidr <cidr>" - Network CIDR to use for service IP addresses. Example: --service-cidr="10.43.0.0/16".
  • For the full list of environment variables check out the official docs

Example - My quick Installation script for a Runtime Fabric cluster

With all of that, this is how I typically spin up a K3s cluster for a quick test of Runtime Fabric. I normally create a VM (in my case an AWS EC2 instance) and run this command:

curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_VERSION=<VERSION> INSTALL_K3S_EXEC="--tls-san <public instance hostname>" sh -s -

Where:
  • INSTALL_K3S_EXEC="—tls-san <public instance hostname>" - This will add the hostname of our server to the certificate of the K8s API server. I normally use an AWS EC2 instance, so this is the public DNS name of the instance. Without specifying the correct SANs, clients connecting from outside the cluster might fail to connect to the API server securely because the certificate will not match the hostname or IP address they are using, leading to TLS validation errors. It's not necessary if you're going to connect to the cluster using kubectl from this node, but I always include it just in case we might need to connect from our laptop for example.
  • K3S_KUBECONFIG_MODE="644" - which is equivalent to add —write-kubeconfig-mode 644 to the previous env variable. I prefer this way, for clarity.
  • INSTALL_K3S_VERSION - with this we specify the K3s version. We need to use a Kubernetes version supported by Runtime Fabric. Remember that the latest K8s version is usually not supported straight away. In order to get the equivalent K3s version we'll check this compatibility matrix in the official docs. For example, we can see that for the K8s version v1.30.0 we'll be using the version v1.30.0+k3s1 in K3s


And, with that, in around 30 seconds we've got our K3s cluster up and running. To check that out run a kubectl get nodes command.



Test the Installation

To verify that our K3s is up and running we'll connect to the cluster with the kubectl. If kubectl cannot connect right after the installation, we’ll need to set the KUBECONFIG env variable. Run the command

export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

Verify your kubeconfig current context now is pointing to your K3s cluster:

kubectl config view



Then, get the nodes of your K3s:

kubectl get nodes




Lastly, remember that the installation of K3s includes Traefik as ingress controller, so you don't have to install anything else, your cluster is ready to install Runtime Fabric. But we'll see that in our next post

Previous Post Next Post