From Zero to Kubernetes Dashboard within Minutes with k3sup and Kontena Lens

Every now and then there are situations you want to setup Kubernetes cluster fast and see easily what is happening inside the cluster. There are some single-node distributions that you can run on your local machine, like minikube, but in some cases it’s not enough and you need real multi-node Kubernetes cluster. This all is possible with k3sup tool and Kontena Lens application.

k3s is lightweight Kubernetes distribution originally created by Darren Shepherd (@ibuildthecloud).

To provision k3s clusters, there’s a handy tool by Alex Ellis (@alexellisuk) called k3sup. k3sup is a tool to get from zero to kubeconfig with k3s on any local or remote VM. Basically, you need k3sup binary and SSH access to machines and you are ready to go.

Kontena Lens is a desktop application to manage and monitor multiple Kubernetes clusters. It will help developers to understand what is happening in the clusters. You can add clusters from your default kubeconfig file or import kubeconfig to Lens app. It’s ideal tool for k3s clusters since nothing is run inside the cluster.

Next, I will show how you can setup k3s cluster easily with k3sup and import it to Kontena Lens within minutes.

Provision servers

Prerequisite for creating Kubernetes cluster is that you have servers running somewhere, it can be on any cloud or on your home lab. If you already have servers running and you have ssh access to them, you can skip this part. I will use DigitalOcean and their `doctl` tool to provision servers, since it’s fast and easy:

$ doctl compute droplet create k3s-demo1 --image ubuntu-19–10-x64 --size 2gb --ssh-keys=<ssh key fingerprint> --region ams3
$ doctl compute droplet create k3s-demo2 --image ubuntu-19–10-x64 --size 2gb --ssh-keys=<ssh key fingerprint> --region ams3
$ doctl compute droplet create k3s-demo3 --image ubuntu-19–10-x64 --size 2gb --ssh-keys=<ssh key fingerprint> --region ams3

When the servers are up and running, we can fetch their ip addresses. Those are needed when we are provisioning Kubernetes to the servers:

$ doctl compute droplet list --format Name,PublicIPv4
Name Public IPv4
k3s-demo1 142.93.133.230
k3s-demo2 165.22.204.221
k3s-demo3 167.172.45.26

Setup k3s Cluster

After the servers are ready, we can start creating k3s Kubernetes cluster with k3sup. You can download k3sup binary by following these instructions.

First, we will create Kubernetes master node. To do that, we need to execute following commands on the command line:

$ export USER=root
$ export IP=142.93.133.230
$ k3sup install --ip $IP --user $USER

We will use the ip of the first server as ip and root as user.

This command will setup Kubernetes master over the ssh to the server and stores KUBECONFIG into the current working directory. We need that later when operating the cluster.

Now we have the master node running. Next, we can join other two nodes to the cluster:

$ export SERVER_IP=142.93.133.230
$ export AGENT_IP=165.22.204.221
$ k3sup join --ip $AGENT_IP --server-ip $SERVER_IP --user $USER
$ export AGENT_IP=167.172.45.26
$ k3sup join --ip $AGENT_IP --server-ip $SERVER_IP --user $USER

This time we are using ip addresses of remaining servers as ip and ip address of the first node as server-ip. Again, k3sup tool will setup Kubernetes components to the servers.

After all nodes are up and running we can check cluster status with kubectl. You should see all nodes with Ready status.

$ KUBECONFIG=kubeconfig kubectl get nodes
NAME STATUS ROLES AGE VERSION
k3s-demo1 Ready master 1m v1.14.6-k3s.1
k3s-demo2 Ready worker 1m v1.15.4-k3s.1
k3s-demo3 Ready worker 1m v1.15.4-k3s.1

Install Kontena Lens

To get better visibility to the cluster, we can start using it with Kontena Lens. You can download Kontena Lens here. If you don’t have a Kontena account yet, you can sign up in the app, otherwise you can just login with your Kontena account credentials.

After you’ve logged in, you can import KUBECONFIG to Lens app. Just copy paste the content of k3sup generated kubeconfig file to Lens app on Add Cluster dialog:

After you’ve imported the kubeconfig, you will see the cluster dashboard:

From cluster settings, it’s possible to customize the cluster name, icon and activate Metrics feature. Metrics feature will install Prometheus and couple of additional components so Lens app can show relevant metrics from nodes and workloads.

One very handy feature of Kontena Lens is that you can use embedded terminal that has correct version of kubectl and pre-configured kubconfig for the cluster in place. For example, you can easily install additional apps into k3s cluster, like openfaas, from the terminal. Openfaas can be installed by running k3sup app install openfaas command. After the installation is complete you can see openfaas services on Lens workloads.

Start Using Openfaas

To start using openfaas, we first need to install openfaas cli with the command (other installation method exists too):

$ curl -sSL https://cli.openfaas.com | sudo -E sh

After that, we can forward the gateway to our machine and login to faas gateway by following the instructions provided by openfaas installation:

Now we are ready to deploy our first function with the command:

$ faas-cli store deploy figlet

And we can see on the Lens dashboard that figlet pod will appear in openfaas-fn namespace.

Summary

Like we saw, installing Kubernetes cluster with k3sup is very easy. With Kontena Lens it’s super handy to manage and operate Kubernetes clusters from your local machine. Kontena Lens is compatible with all Kubernetes clusters, so you can use it with managed Kubernetes services (GKE, EKS, AKS, DO etc) too. If you want to setup full version of Kubernetes on your own datacenter or any cloud, you can check out Kontena Pharos. It makes it super easy and it comes with useful add-ons.

Cloud-native full-stack developer. Core developer of https://k8slens.dev