Ever wondered how to easily setup free kubernetes on VPS? We walk you through how to do this for any VPS or dedicated server with root access. For practical reasons we are using CharityHost.org VPS with public IP connections for simplicity purposes. You can also add a loadbalancer with keepalived or haproxy on a front facing VPS and use private networking for the k3s nodes but for the purposes of this tutorial we focus on the k8s k3s installation.
Note: On CharityHost.org there is a simple script
Login as root to k3s-01 node.
ssh -l root k3s-01.spectrohost.com
Run updates and restart for best practice patching to start:
apt-get update
apt-get upgrade -y
shutdown -hr now
Once the VM is up again, login as root via ssh again:
ssh -l root k3s-01.spectrohost.com
Disable UFW firewall if active or reference k3s requirements for required open ports and adjust your firewall accordingly:
ufw disable
Repeat these 4 steps above on all VM that will join the k3s kubernetes cluster as nodes.
Quick-start Install k3s on the k3s-01.spectrohost.com for the first master node:
Note: This can also be done automatically running a "Recipe" for k3s installation by connecting to the client area then accessing the virtualizor VDS panel "Installation" menu):
curl -sfL https://get.k3s.io | sh -
It will result in output like this:
[INFO] systemd: Starting k3s
Check the node with kubectl cli:
kubectl get node
Expect output like this:
NAME STATUS ROLES AGE VERSION
k3s-01.spectroweb.com Ready control-plane,master 86s v1.30.4+k3s1
While still connected, get the Node Token from your first node (master node) and copy it:
cat /var/lib/rancher/k3s/server/node-token
Logout and then login to each additional VM via ssh to connect it to the first master node and add them to the k3s cluster as agents:
ssh -l root k3s-02.spectrohost.com
Attention, this command includes the node-token you got in step 3 above. Past your node token replacing and replace the k3s-01.spectrohost.com with your actual k3s resolvable A record for the 1st node (or however suitable, use the public or private IP address) in the following command.
curl -sfL https://get.k3s.io | K3S_URL=https://k3s-01.spectrohost.com:6443 K3S_TOKEN= sh -
Expect the tail end of the output to be like this:
[INFO] Host iptables-save/iptables-restore tools not found
[INFO] Host ip6tables-save/ip6tables-restore tools not found
[INFO] systemd: Starting k3s-agent
Verify both nodes are online, the ks-01 master node and the ks-02 agent worker node. Login to ks-01 via ssh and run command:
kubectl get nodes
Expect 2 nodes to be listed as ready:
NAME STATUS ROLES AGE VERSION
k3s-01.spectroweb.com Ready control-plane,master 21m v1.30.4+k3s1
k3s-02.spectroweb.com Ready <none> 4m39s v1.30.4+k3s1
And that's all there is to installing a 2+ node kubernetes k3s cluster. Futher tutorials and research would be needed to walk through the lifecycle processes for a kubernetes containerized application deployment.
Thank you!
Feedback welcomed!
References:
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
To install Kubernetes K3s on a single or multiple VPS, follow these steps:
1. Prepare Your VPS (Single or Multiple)
sudo apt update && sudo apt upgrade -y
2. Install K3s on the Master Node
3. Get the Join Token (for Multiple Nodes)
4. Install K3s on Worker Nodes (for Multiple Nodes)
<MASTER_IP>
with the IP address of the master and<TOKEN>
with the join token:5. Verify the Cluster
You should now see all nodes (master and workers) listed, ready to run your Kubernetes workloads.