Install K3S Server

In this tutorial, I’m not going to show you how to install linux on a Raspberry Pi, or on a VM(virtualbox, qemu/kvm), there are tons of guides out there on the internet that already do that. We’ll skip straight into installing K3S and some Open Source applications that we can run on our cluster.

So let’s get straight into installing K3S.

Install K3S Server on the Master Node

  1. Set the Environment Variables

    Before we actually install K3S, let’s setup our Environment Variables. The first line will enable us to run kubectl without being root, while the second line tells the installer not install it’s native loadbalancer(servicelb) and proxy(traefik). We’ll manually install Metalb as the loadbalancer and Nginx as a proxy.

    $ export K3S_KUBECONFIG_MODE="644"
    $ export INSTALL_K3S_EXEC=" --no-deploy servicelb --no-deploy traefik"
    
  2. Install K3S

    With that out of the way, let’s install K3S server, and confirm it’s up and running:

    basedmeezus@K3SMaster:~$ curl -sfL https://get.k3s.io | sh -
    [sudo] password for basedmeezus: 
    [INFO]  Finding release for channel stable
    [INFO]  Using v1.22.7+k3s1 as release
    [INFO]  Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.22.7+k3s1/sha256sum-amd64.txt
    [INFO]  Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.22.7+k3s1/k3s
    [INFO]  Verifying binary download
    [INFO]  Installing k3s to /usr/local/bin/k3s
    [INFO]  Skipping installation of SELinux RPM
    [INFO]  Creating /usr/local/bin/kubectl symlink to k3s
    [INFO]  Creating /usr/local/bin/crictl symlink to k3s
    [INFO]  Creating /usr/local/bin/ctr symlink to k3s
    [INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
    [INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
    [INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
    [INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
    [INFO]  systemd: Enabling k3s unit
    Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service.
    [INFO]  systemd: Starting k3s
    

    Now to confirm the K3S system service is up and running:

    basedmeezus@K3SMaster:~$ sudo systemctl status k3s
    [sudo] password for basedmeezus: 
    ● k3s.service - Lightweight Kubernetes
     Loaded: loaded (/etc/systemd/system/k3s.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-03-09 20:57:01 UTC; 16min ago
    

    Now let’s confirm all the default services and pods are up and running:

    basedmeezus@K3SMaster:~$ kubectl get all -A
    NAMESPACE     NAME                                          READY   STATUS    RESTARTS   AGE
    kube-system   pod/local-path-provisioner-84bb864455-4r75p   1/1     Running   0          40s
    kube-system   pod/coredns-96cc4f57d-fj4q2                   1/1     Running   0          40s
    kube-system   pod/metrics-server-ff9dbcb6c-xkvng            1/1     Running   0          40s
    
    NAMESPACE     NAME                     TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                  AGE
    default       service/kubernetes       ClusterIP   10.43.0.1      <none>        443/TCP                  54s
    kube-system   service/kube-dns         ClusterIP   10.43.0.10     <none>        53/UDP,53/TCP,9153/TCP   51s
    kube-system   service/metrics-server   ClusterIP   10.43.40.210   <none>        443/TCP                  50s
    
    NAMESPACE     NAME                                     READY   UP-TO-DATE   AVAILABLE   AGE
    kube-system   deployment.apps/local-path-provisioner   1/1     1            1           51s
    kube-system   deployment.apps/coredns                  1/1     1            1           51s
    kube-system   deployment.apps/metrics-server           1/1     1            1           50s
    
    NAMESPACE     NAME                                                DESIRED   CURRENT   READY   AGE
    kube-system   replicaset.apps/local-path-provisioner-84bb864455   1         1         1       41s
    kube-system   replicaset.apps/coredns-96cc4f57d                   1         1         1       41s
    kube-system   replicaset.apps/metrics-server-ff9dbcb6c            1         1         1       41s
    
  3. Get the Node Token Now to Install the K3S Agents on Worker Nodes, we’ll need the access token. The access token can be retrieved by running the following command:

    basedmeezus@K3SMaster:~$ sudo cat /var/lib/rancher/k3s/server/node-token
    K109cdd14ff6974270f501e2660958f45dfff65a2311408e4e2ece7960b0dbef0ab::server:e0db12c2f18dfe7720874bb0485724a0