You are not logged in.
Pages: 1
K3S v1.32.5+k3s1 tested on Devuan 5 arm64 and amd64
It works the same as the original script, performs the installation (server/controller or worker/agent node) creates the service and creates uninstall script.
This script should work with Systemd systems or any other SysVinit Debian based distro as well, but I never tried, I kept the Systemd parts in order to make it easier for me to mod it focusing only on what I need change to make it work with SysVinit, if someone else wants to improve this script then please do so.
All the K3S_* environment variables are accepted. you can use them if applicable, the script will run in local mode so the environment variables must be indicated before the install script file as the examples below.
Main server/controller install:
K3S_TOKEN="MySecr3tT0k3n" K3S_ROLE=server FINAL_EXEC_OPTIONS="--cluster-init --bind-address 192.168.1.xxx --write-kubeconfig-mode 644" ./k3s-sysvinit-install.sh
#This will install K3S as server/controller, listen to the address 192.168.1.xxx only (useful when you have more than one IP addresses), will write the config in mode 644 and will use the specified token to create a cluster.
Second server/controller install:
K3S_TOKEN="MySecr3tT0k3n" K3S_ROLE=server FINAL_EXEC_OPTIONS="--server https://192.168.1.xxx:6443 --write-kubeconfig-mode 644" ./k3s-sysvinit-install.sh
#This will install a second (third, etc.) server/controller, will write the config in mode 644 and will use the specified token to join an existing cluster on 192.168.1.xxx
#Server Service:
sudo service k3s status/start/stop/restart
Worker node install:
K3S_TOKEN="MySecr3tT0k3n" K3S_ROLE=agent K3S_URL=https://192.168.1.xxx:6443 ./k3s-sysvinit-install.sh
#This will install K3S in worker mode and will connect to the cluster controller on 192.168.1.xxx:6443 using the specified token.
#Worker Service:
sudo service k3s-agent status/start/stop/restart
Download link:
https://drive.proton.me/urls/4GKT3SBAQC#syB0ofJ2LlSF
Troubleshooting:
If when you execute:
$ k3s kubectl get nodes
You get an error with last text line that says:
Unable to connect to the server: tls: failed to verify certificate: x509: certificate signed by unknown authority
Or when when you execute:
$ kubectl get nodes
You get this error that says:
The connection to the server localhost:8080 was refused - did you specify the right host or port?
And when you try to install helm/charts you get this error:
Error: Kubernetes cluster unreachable: Get "http://localhost:8080/version": dial tcp [::1]:8080: connect: connection refused
This happens because they are trying to communicate with the k3s server/controller without the proper settings/certificate.
Do this to fix it:
mkdir ~/.kube
sudo k3s kubectl config view --raw | tee ~/.kube/config
chmod 600 ~/.kube/config
echo "export KUBECONFIG=~/.kube/config" >> .bashrc
source ~/.bashrc
rev01:
- Added the K3S version tested.
- Added K3S_ROLE=server env. variable, this is not required by the original script but I have notice that having different nodes working as controllers or workers but with the command "sudo service k3s/-agent status" printing just "k3s is running/not running..." on any of them this is prone to errors/mistakes, so now if I specify the role as server or agent for the install then for example the command "sudo service k3s/-agent status" will print "k3s-server is running/not running..." for servers/controller or "k3s-agent is running/not running..." for worker nodes.
Also please notice/remember that the service command remains just "k3s" for server/controller but still "k3s-agent" for workers, that's how k3s works.
- Added the specific example how to install and join a second or third, etc, controller to an existing cluster controller. (yeah, I don't like when other people gives non-clear instructions"
- Added Troubleshooting, fix for "k3s kubectl get nodes" error, "kubectl get nodes" error and "helm connection refused" error.
Last edited by joser (2025-05-29 02:30:57)
Offline
Pages: 1