Reading Time: 5 minutes

What is Rancher K3s?

K3S

K3s is an official Cloud Native Computing Foundation sandbox project that brings a lightweight, fully compliant Kubernetes distribution designed for lower resource production models like remote locations or on an IoT device. When used in conjunction with Rancher, K3s can easily be managed from within the Rancher orchestration platform.

What is Rancher?

Rancher

Rancher is a complete software stack used to deploy containers. It addresses the operational and security hurdles of operating multiple Kubernetes clusters across an infrastructure. Rancher provides DevOps teams with multiple integrated tools for running containerized workloads. 

High-Availability K3s Server with an External DB Single server clusters can meet various use cases. Still, for environments where the Kubernetes control plane uptime is critical, you can run K3s in an HA configuration. An HA K3s cluster consists of two or more server nodes that will serve the Kubernetes API and run other control plane services An external datastore (as opposed to the embedded SQLite datastore used in single-server setups)

Architecture

K3s can be configured in multiple ways. It can be used as a single server setup using an embedded database such as SQLite or a high availability K3s server cluster using an external database. In the image shown below, the framework is demonstrated in a high availability setup. 

Prerequisites

  • Access to the root user or a user with sudo privileges
  • A unique hostname for each node
  • A Linux based OS

Minimum Hardware Recommendations

  • 512 MB RAM (1 GB recommend)
  • 1 CPU at minimum
  • SSD drive preferred

Networking

  • An open port (6443) used for node accessibility
  • If metrics are desired, open port 10250 on each node
  • If Flannel VXLAN is used, open UDP port 8472. This port should not be available externally

Clusters

If clustering is desired, run a high availability setup using an external production database similar to the ones listed below.

  • MySQL
  • PostgreSQL
  • etcd

CPU & Memory

These are the recommended settings for deploying K3s in a clustered setting.

DEPLOYMENT SIZE

NODES

VCPUS

RAM

Small

Up to 10

2

4 GB

Medium

Up to 100

4

8 GB

Large

Up to 250

8

16 GB

X-Large

Up to 500

16

32 GB

XX-Large

500+

32

64 GB

Disks

  • SSD drive preferred

Network

  • Increase CIDR subnet size, so pod IPs are available. Accomplished this using the --cluster-cidr option upon starting the K3s server

Database

  • K3s supports multiple databases, including MySQL, PostgreSQL, MariaDB, and etcd. Here are sizing recommendations needed for a database to run on a large cluster

DEPLOYMENT SIZE

NODES

VCPUS

RAM

Small

Up to 10

1

2 GB

Medium

Up to 100

2

8 GB

Large

Up to 250

4

16 GB

X-Large

Up to 500

8

32 GB

XX-Large

500+

16

64 GB

Installation

Server

We have two main options when installing K3s. We can use a script or install it from a binary file. The simplest method is using the following command.

curl -sfL https://get.k3s.io | sh -

Multiple variables can be employed to extend the configurability of this installation. After running this script, the K3s service will be automatically configured to restart after the node reboots or if the task crashes or is killed off. 

The following extra utilities are installed as well during this process.

  • kubectl 
  • crictl 
  • ctr 
  • k3s-killall.sh
  • k3s-uninstall.sh

Additionally, the kubectl app installed by K3s will automatically use a newly created kubeconfig file written to /etc/rancher/k3s/k3s.yaml.

Nodes

To install K3s on each worker node, run the installation script using the K3S_URL and K3S_TOKEN variables. Below is an example showing how to join a worker node: and add them to the cluster,

curl -sfL https://get.k3s.io | K3S_URL=https://servername:6443 K3S_TOKEN=nodetoken sh -

Using the K3S_URL parameter prompts K3s to run in worker mode. This indicates that the K3s agent will register the node with the K3s server listening on the provided URL. The K3S_TOKEN value is stored at /var/lib/rancher/k3s/server/node-token on your server node.

Server Start

The installation script noted above will detect which service type your OS is using and initiate the service. If using systemd, a log file will be created in /var/log/syslog and can be viewed using the journalctl -u k3s command.

Below is an example service unit for the k3s.service file if our OS uses systemd.

[Unit]
Description=Lightweight Kubernetes
Documentation=https://k3s.io
After=network-online.target

[Service]
Type=notify
EnvironmentFile=/etc/systemd/system/k3s.service.env
ExecStart=/usr/local/bin/k3s server
KillMode=process
Delegate=yes
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Restart=always
RestartSec=5s

[Install]
WantedBy=multi-user.target

Configuration

Auto-Deploying Manifest Files

A manifest file can be placed in the following location.

/var/lib/rancher/k3s/server/manifests

K3s will automatically deploy the manifest file in the same way the kubectl apply command is used to deploy a manifest file. 

Upgrade

To upgrade an older version of k3s, we can re-run the original installation script utilizing the same flags noted in the Installation section above.

curl -sfL https://get.k3s.io | sh -

If we want to upgrade K3s to a specific version, we can run the following command.

curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v.y.z-rc1 sh -

To upgrade k3s manually:

  1. Download the K3s version from the release page at GitHub.
  2. Install it to /usr/local/bin/k3s (or a location of your choosing.
  3. Stop the old version of K3s, then start the new version manually using the following command.
systemctl restart k3s

Uninstalling

If k3s was installed using the install.sh script, an uninstall script is automatically created during the installation process. This uninstall script is located on our server node at /usr/local/bin/k3s-uninstall.sh. (or as k3s-agent-uninstall.sh).

Known Issues

If using iptables in nftables mode rather than the legacy version, you may encounter issues. Rancher recommends using the newer versions of iptables (1.6.1+) to circumvent any problems.

Conclusion

K3s is a new, versatile, full-stack K8s platform used to simplify the deployment of either standalone or clustered server deployment. Because k3s is designed for lower resource production models like remote locations or on IoT devices, it allows for a fully compliant Kubernetes distribution to be taken advantage of. When used in conjunction with Rancher, K3s can easily be managed from within the Rancher orchestration platform.

Reserve Your Spot Today!

We pride ourselves on being The Most Helpful Humans In Hosting™!

Our Support Teams are filled with experienced Linux technicians and talented system administrators who have intimate knowledge of multiple web hosting technologies, especially those discussed in this article.

Should you have any questions regarding this information, we are always available to answer any inquiries with issues related to this article, 24 hours a day, 7 days a week 365 days a year.

If you are a Fully Managed VPS server, Cloud Dedicated, VMWare Private Cloud, Private Parent server, Managed Cloud Servers, or a Dedicated server owner and you are uncomfortable with performing any of the steps outlined, we can be reached via phone at @800.580.4985, a chat or support ticket to assisting you with this process.

About the Author: David Singer

I am a g33k, Linux blogger, developer, student, and former Tech Writer for Liquidweb.com. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Have Some Questions?

Our Sales and Support teams are available 24 hours by phone or e-mail to assist.

1.800.580.4985
1.517.322.0434

Latest Articles

What is a Webhook?

Read Article

Microsoft Exchange Server Security Update

Read Article

How to Monitor Your Server in WHM

Read Article

How to Monitor Your Server in WHM

Read Article

How to Fix Typical WordPress Errors

Read Article