Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How to quick setup lightweight k3s kubernetes on 2 or more VM/VDS/VPS/dedicated servers
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

How to quick setup lightweight k3s kubernetes on 2 or more VM/VDS/VPS/dedicated servers

CharityHost_orgCharityHost_org Member, Patron Provider
edited September 14 in Tutorials

How to quick setup lightweight k3s kubernetes on 2 or more VM/VDS/VPS/dedicated servers

Tutorial by:

https://charityhost.org/virtual-dedicated-servers

Summary:

Ever wondered how to easily setup free kubernetes on VDS/VPS? We walk you through how to do this practically for any VDS/VPS or dedicated server with root access. For practical reasons we are using CharityHost.org VDS with public IP connections for simplicity purposes. It is possible to create a 2+ node k3s kubernetes cluster that are loadbalanced with our managed loadbalancer connecting through our Public or Private network.

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
    

    Note: CharityHost.org VDS includes a Firewall you can manage for your VDS to secure connections on public and private links.

    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

Thanked by 1Patriarch

Comments

Sign In or Register to comment.