LetHostTalk
How to install Kubernetes k3s on single or multiple VPS — LetsHostTalk - Web Hosting Forum
HostNamaste.com

How to install Kubernetes k3s on single or multiple VPS

CharityHost_orgCharityHost_org Member, Provider

Summary:

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.

Requirements:

  • Basic knowledge of kubernetes
  • Basic/intermediate knowledge on Linux OS and ssh
  • 1 or more root access servers on a private or public network
  • Reference all requirements needed for k3s here: https://docs.k3s.io/installation/requirements

Setup VM's

  1. For this tutorial we are using 2 x Debian 12 with 1 vCPU 2 GB ram 55 GB SSD
  2. In CharityHost.org we created the 2 hosts with server names: k3s-01.spectrohost.com and k3s-02.spectrohost.com (spectrohost.com is an externally managed and publicly resolvable domain for simplicity purposes)
  3. We add A records on the public domain DNS zone pointing to each server IP for
    k3s-01.spectrohost.com and k3s-02.spectrohost.com
  4. Once those are VM are deployed , A records resolve, and you are ready you would proceed with the k3s first node installation if you just want all communication to go through public addresses, or make sure you have private addressing on the same network on your VM's as well. (At CharityHost.org this is by sending a support ticket request to add Private IP addresses to each VM)

Prepare your VM's

Note: On CharityHost.org there is a simple script

  1. Login as root to k3s-01 node.

    ssh -l root k3s-01.spectrohost.com
    
  2. Run updates and restart for best practice patching to start:

    apt-get update
    apt-get upgrade -y
    shutdown -hr now
    
  3. Once the VM is up again, login as root via ssh again:

    ssh -l root k3s-01.spectrohost.com

  4. 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.

Install k3s on the first VM node to be the Master node:

  1. 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
    
  2. 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
    
  3. While still connected, get the Node Token from your first node (master node) and copy it:

    cat /var/lib/rancher/k3s/server/node-token
    
  4. 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
    
  5. 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
    
  6. 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:

https://docs.k3s.io/installation/requirements

Comments

  • LawrenceLawrence Member, Provider

    To install Kubernetes K3s on a single or multiple VPS, follow these steps:

    1. Prepare Your VPS (Single or Multiple)

    • Ensure each VPS has at least 1GB RAM and a compatible Linux distribution (Ubuntu, CentOS, etc.).
    • Update system packages: sudo apt update && sudo apt upgrade -y

    2. Install K3s on the Master Node

    • Run this command on the master VPS:
      curl -sfL https://get.k3s.io | sh -
      
    • This installs K3s and starts the master node.

    3. Get the Join Token (for Multiple Nodes)

    • On the master VPS, find the token needed to join other nodes:
      sudo cat /var/lib/rancher/k3s/server/node-token
    • Copy this token to use on each additional node.

    4. Install K3s on Worker Nodes (for Multiple Nodes)

    • Run this command on each worker VPS, replacing <MASTER_IP> with the IP address of the master and <TOKEN> with the join token:
      curl -sfL https://get.k3s.io | K3S_URL=https://<MASTER_IP>:6443 K3S_TOKEN=<TOKEN> sh -
    • This connects each worker node to the master.

    5. Verify the Cluster

    • On the master node, check if the nodes are connected:
      kubectl get nodes

    You should now see all nodes (master and workers) listed, ready to run your Kubernetes workloads.

Sign In or Register to comment.
                                                               KVM VPS