Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Install K3s Agent On Ubuntu 20.04


Get Kubernetes Token

SSH into one of your controller servers, and run:

sudo cat /var/lib/rancher/k3s/server/node-token


Now that we have our token, SSH into the server you wish to become an agent, and run the following script (addig the token as a variable).


sudo curl -sfL | K3S_URL=https://$LOAD_BALANCER_IP:6443 K3S_TOKEN=$TOKEN sh -

Testing It Worked

If you now log into one of your master/controller servers and run:

sudo k3s kubectl get node

... then you will see your agent, like below:

NAME          STATUS   ROLES                  AGE     VERSION
kube1         Ready    control-plane,master   94m     v1.21.1+k3s1
kube-agent1   Ready    <none>                 8m20s   v1.21.1+k3s1
kube2         Ready    control-plane,master   92m     v1.21.1+k3s1
kube3         Ready    control-plane,master   43m     v1.21.1+k3s1

Error Message When Running Command On Agent

If you run the command above on the agent, instead of one of the master/controller servers, then you will get the following error message:

The connection to the server localhost:8080 was refused - did you specify the right host or port?

In order to get the command working on the agents, you need to follow the configuration section on my post on how to install kubectl on your local machine.


Last updated: 23rd June 2021
First published: 23rd June 2021