Skip to main content

Install k3s

To install k3s I use k3sup, which automates the process of sshing into the server and running the install script.

Install kube tools on your local machine​

warning

All packages need to be installed on your local machine.

kubectl and utilities​

To operate the cluster, you need to install kubectl. I also use other tools like:

  • kubeseal to encrypt secrets
  • kubectx to switch between clusters
  • kustomize to manage and patch Kubernetes objects
  • k9s to have a terminal UI for Kubernetes
  • helm to manage Kubernetes applications
  • flux to manage GitOps

You can install all of them by running:

brew install kubectl kubeseal kubectx kustomize k9s helm fluxcd/tap/flux

k3sup​

Installing k3sup is easy. Just run the following command:

curl -sLS https://get.k3sup.dev | sh
sudo install k3sup /usr/local/bin/

Install k3s​

The following commands will install a multi-master (HA) k3s cluster with embedded etcd. You can find out more about the installation options in the k3sup documentation.

Install the first node with:

export SERVER_IP=10.0.2.10
export USER=lorenzo

k3sup install \
--ip $SERVER_IP \
--user $USER \
--cluster \
--k3s-version v1.33.1+k3s1 \
--ssh-key ~/.ssh/id_ed25519 \
--local-path ~/.kube/config

k3sup will automatically copy the kubeconfig in the path you specify with --local-path. The default path for kubectl is ~/.kube/config.

Now try to access the cluster with:

kubectl get nodes

You should see something like this:

NAME           STATUS   ROLES                       AGE   VERSION
k8s-master-1 Ready control-plane,etcd,master 38h v1.33.1+k3s1

Once you have the master node up and running, you can let the other nodes join the cluster with:

export USER=lorenzo
export SERVER_IP=10.0.2.10
export NEXT_SERVER_IP=10.0.2.11

k3sup join \
--ip $NEXT_SERVER_IP \
--user $USER \
--server-user $USER \
--server-ip $SERVER_IP \
--server \
--k3s-version v1.33.1+k3s1 \
--ssh-key ~/.ssh/id_ed25519

And for the last node:

export USER=lorenzo
export SERVER_IP=10.0.2.10
export NEXT_SERVER_IP=10.0.2.12

k3sup join \
--ip $NEXT_SERVER_IP \
--user $USER \
--server-user $USER \
--server-ip $SERVER_IP \
--server \
--k3s-version v1.33.1+k3s1 \
--ssh-key ~/.ssh/id_ed25519

k3sup will automatically use the join token generated by the master node.

Now you should see all the worker nodes together with the master:

NAME           STATUS   ROLES                       AGE   VERSION
k8s-master-1 Ready control-plane,etcd,master 38h v1.33.1+k3s1
k8s-master-2 Ready control-plane,etcd,master 38h v1.33.1+k3s1
k8s-master-3 Ready control-plane,etcd,master 38h v1.33.1+k3s1

To see more installation options, you can check the k3sup GitHub page.