Kubernetes

Deploying k3s

Using k3s to deploy a Kubernetes Cluster

Installing the master

To deploy Kubernetes, we need to SSH into the VMs. Assuming we are using the official docker image with fish integration, we can write detee-cli vm ssh master and hit the TAB key. This will autocomplete the UUID needed to identify the VM and to SSH. The command allows the --just-print parameter if we want to show the SSH command without connecting.

root@e2d98b4ae6e1 /# detee-cli vm ssh 92ceeba2-0f2c-4dac-8a0c-942a52e9f074 --just-print
To SSH into k3s-master (UUID: 92ceeba2-0f2c-4dac-8a0c-942a52e9f074), run the following command:
    ssh -i /root/.ssh/id_ed25519 -p 22 root@173.234.136.155
root@e2d98b4ae6e1 /# detee-cli vm ssh 92ceeba2-0f2c-4dac-8a0c-942a52e9f074
Running SSH command: ssh -i /root/.ssh/id_ed25519 -p 22 root@173.234.136.155
[root@k3s-master ~]#

On the k3s-master node, we should first upgrade the software and install curl:

pacman -Syu --noconfirm
pacman -S curl --noconfirm

After this we can install k3s by running:

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

Installing workers

After the master node got installed, we can get the token of the master node to install additional nodes in this cluster. You can find the token in the file /var/lib/rancher/k3s/server/node-token on the master node:

[root@k3s-master ~]# cat /var/lib/rancher/k3s/server/node-token
K10cc4e73cdf765636f89e34ec84c7698972bf52499fdd162acd60a084ed70ceca6::server:89e69f56769aca094fc5bc804efcc7e1

Now we can just get the IP of the master node, and SSH into k3s-node-1 to install it as a worker node in the cluster:

root@e2d98b4ae6e1 /# FORMAT=YAML detee-cli vm inspect 92ceeba2-0f2c-4dac-8a0c-942a52e9f074 | grep ipv4
public_ipv4: 173.234.136.155
~# detee-cli vm ssh d811af7e-83a0-40fe-b83f-a4fec2cc7608
Running SSH command: ssh -i /root/.ssh/id_ed25519 -p 22 root@173.234.137.17
[root@k3s-node-1 ~]# curl -sfL https://get.k3s.io | K3S_URL=https://173.234.136.155:6443 K3S_TOKEN=K10cc4e73cdf765636f89e34ec84c7698972bf52499fdd162acd60a084ed70ceca6::server:89e69f56769aca094fc5bc804efcc7e1 sh -
  # ... log removed
[INFO]  systemd: Starting k3s-agent
[root@k3s-node-1 ~]#

As you probably observed, the command for the worked node is:

curl -sfL https://get.k3s.io | K3S_URL=https://173.234.136.155:6443 K3S_TOKEN=K10cc4e73cdf765636f89e34ec84c7698972bf52499fdd162acd60a084ed70ceca6::server:89e69f56769aca094fc5bc804efcc7e1 sh -

Listing all nodes

You can go ahead and run this command also on the 3rd node. After that, log into k3s-master and check the available nodes with kubectl:

[root@k3s-master ~]# kubectl get node
NAME         STATUS   ROLES                  AGE     VERSION
k3s-master   Ready    control-plane,master   16m     v1.32.3+k3s1
k3s-node-1   Ready    <none>                 3m16s   v1.32.3+k3s1
k3s-node-2   Ready    <none>                 3s      v1.32.3+k3s1