Deploying a Lightweight K3s Kubernetes Cluster on a Single VPS: From Installation to First Application
TL;DR
In this detailed guide, we will step-by-step configure a lightweight K3s Kubernetes cluster on a single Virtual Private Server (VPS). You will learn how to prepare the server, install K3s, deploy your first test application, and ensure its availability via an Ingress controller with TLS. This material is aimed at VPS owners who need a simple and efficient way to orchestrate containerized applications without excessive resources or the complexity of full-scale Kubernetes.
- VPS Preparation: installing basic utilities, configuring security (SSH, Fail2ban, Firewall).
- K3s Installation: deploying a K3s server version 1.31.x on Ubuntu 24.04 LTS.
- Configuration: setting up cluster access, deploying the Traefik Ingress controller and automatic TLS with Caddy.
- Application Deployment: launching a test web application and publishing it to the outside world.
- Maintenance: recommendations for backups, updates, and troubleshooting common issues.
What We Are Setting Up and Why
We will be deploying K3s — a lightweight, certified Kubernetes distribution developed by Rancher Labs. Unlike "big" Kubernetes, K3s is designed to operate in resource-constrained environments, such as IoT devices, edge computing, or, in our case, a single VPS. It is ideal for developers, startups, and enthusiasts who need a reliable tool for container orchestration without the complexity and resource intensity inherent in standard Kubernetes installations.
Ultimately, you will get a fully functional Kubernetes cluster on a single server, capable of running and managing your containerized applications. This will allow you to leverage all the benefits of Kubernetes (self-healing, declarative management, scaling) without having to invest in expensive cloud services or maintain a complex infrastructure of multiple servers. You will be able to easily deploy web services, databases, game servers, and other applications, ensuring their stable operation and availability.
Alternatives exist, such as fully managed cloud Kubernetes services (EKS, GKE, AKS) or traditional Kubernetes installations using kubeadm on multiple VPS. Cloud services are convenient but expensive and tie you to a specific provider. Traditional Kubernetes requires more resources, setup time, and deep knowledge to maintain. K3s on your own VPS offers a golden mean: you retain full control over the infrastructure, minimize costs, and get a significantly simplified, yet full-featured Kubernetes experience. This is an excellent choice for those who want to learn Kubernetes or deploy small/medium projects where every dollar and megabyte of RAM counts.
What VPS Configuration is Needed for This Task
Choosing the right VPS configuration is critical for the stable operation of K3s and your applications. K3s itself is quite lightweight, but the applications you run on it may require significant resources.
Minimum Requirements for K3s (without applications):
- CPU: 1 core (e.g., Intel Xeon E3/E5).
- RAM: 1 GB (for K3s and basic OS).
- Disk: 20 GB NVMe/SSD (for OS, K3s, and storing basic container images).
- Network: 100 Mbps.
Recommended VPS Plan for a Single K3s Cluster with Multiple Applications (e.g., web service + DB):
- CPU: 2-4 cores (e.g., Intel Xeon E3/E5 or AMD EPYC).
- RAM: 4-8 GB.
- Disk: 50-100 GB NVMe/SSD (for OS, K3s, container images, logs, and application data).
- Network: 1 Gbps or higher.
A VPS with the specified characteristics can be obtained from various providers. For example, VPS with the specified characteristics will suit most tasks. If you plan to run resource-intensive databases, high-load web services, or game servers with many players, consider an option with 8+ GB RAM and 4+ CPU cores.
When a dedicated server is needed, not a VPS
A dedicated server becomes justified when your applications require maximum performance, guaranteed resources, a very large amount of disk space (e.g., for storing backups or media files), or when you run many K3s clusters (e.g., for different clients). If you see that your VPS is constantly loaded at 80-90% CPU or RAM, or you need more than 100-200 GB of fast storage, then transitioning to a dedicated server, such as a suitable dedicated server, will be a logical step. For most single K3s installations, a VPS will be more than sufficient at the start.
Location: what it affects
The choice of VPS location affects the latency between your server and end-users. The closer the server is to your target audience, the faster pages will load and services will respond. For example, for users from Europe, it is better to choose a VPS in Germany, the Netherlands, or Finland. For Asia — Singapore or Hong Kong. Also, consider the legal aspects and data protection laws in the chosen country.
Server Preparation
Before installing K3s, it is necessary to perform minimal server configuration to ensure security and ease of use. We will be using Ubuntu Server 24.04 LTS.
1. SSH Connection and User Creation
Connect to your VPS as the root user, using the IP address and password provided by your provider. Then, create a new user with sudo privileges for daily operations:
# Create a new user (replace 'your_user' with your desired name)
sudo adduser ваш_пользователь
# Add the user to the sudo group
sudo usermod -aG sudo ваш_пользователь
Exit the root session and log in as the new user.
2. SSH Key Configuration
For enhanced security and convenience, use SSH keys instead of passwords. On your local machine, generate a key (if you don't have one):
# On your local machine
ssh-keygen -t rsa -b 4096
Copy the public key to the server:
# On your local machine (replace IP and username)
ssh-copy-id ваш_пользователь@ваш_ip_сервера
Now you can disable password authentication for SSH. Edit the /etc/ssh/sshd_config file:
# Open the SSH configuration file
sudo nano /etc/ssh/sshd_config
Find and change the following lines (or add them if missing):
# /etc/ssh/sshd_config
PasswordAuthentication no
PermitRootLogin no
Restart the SSH service:
# Restart the SSH service
sudo systemctl restart sshd
3. System Update and Basic Utility Installation
Be sure to update all packages and install necessary utilities such as curl, wget, git, unzip, net-tools, which may be needed for installation and debugging.
# Update package list
sudo apt update
# Upgrade all installed packages
sudo apt upgrade -y
# Install basic utilities
sudo apt install -y curl wget git unzip net-tools htop
4. Firewall Configuration (UFW)
Enable UFW (Uncomplicated Firewall) and allow only the necessary ports. For K3s and SSH:
- SSH: 22/tcp
- K3s Server: 6443/tcp (Kubernetes API server)
- HTTP/HTTPS: 80/tcp, 443/tcp (for Ingress controller and applications)
# Allow SSH
sudo ufw allow ssh
# Allow K3s API port
sudo ufw allow 6443/tcp
# Allow HTTP and HTTPS for web applications
sudo ufw allow http
sudo ufw allow https
# Enable firewall
sudo ufw enable
# Confirm 'y'
Check firewall status:
# Check UFW status verbose
sudo ufw status verbose
5. Fail2ban Installation
Fail2ban protects the server from brute-force attacks by blocking IP addresses from which too many failed login attempts occur.
# Install Fail2ban
sudo apt install -y fail2ban
# Start and enable Fail2ban autostart
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
The basic Fail2ban configuration is already quite effective. For more fine-grained tuning, you can copy and edit the /etc/fail2ban/jail.conf file to /etc/fail2ban/jail.local.
# Copy the base config for changes
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
# Open for editing (optional, for configuration)
sudo nano /etc/fail2ban/jail.local
Ensure that the [sshd] section is active (enabled = true).
Software Installation — Step-by-step
In this section, we will install K3s on our prepared VPS. We will use the latest stable version of K3s for 2026, assuming it will be a version in the 1.31.x - 1.32.x range, compatible with Kubernetes 1.31.x - 1.32.x. For convenience, we will use the official installation script.
1. K3s Server Installation
K3s can be installed with a single command. The script will automatically download the binaries, configure system services, and start K3s. By default, K3s uses the containerd container engine, which will be installed automatically.
# Install K3s server (assuming version 1.31.x for 2026)
# Use INSTALL_K3S_VERSION to fix the version and avoid automatic updates to major versions.
# INSTALL_K3S_EXEC="--disable traefik" disables the built-in Traefik, as we will use Caddy/Ingress.
# K3S_TOKEN is the token that will be used to add agents if you decide to expand the cluster.
# Copy it after installation.
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.31.5+k3s1" K3S_TOKEN="SUPERSECRETTOKEN12345" sh -s - --disable traefik
This command will install K3s, disable the built-in Traefik Ingress controller (we will use a different one), and start all necessary components. The process may take a few minutes.
2. Checking K3s Status
After installation, ensure that K3s is running and working correctly. K3s is installed as a system service.
# Check K3s service status
sudo systemctl status k3s
You should see the status active (running).
3. Configuring KUBECONFIG Environment Variable
To interact with the Kubernetes cluster (via kubectl), you need to specify the path to the configuration file. K3s places it at /etc/rancher/k3s/k3s.yaml.
# Create directory for kubeconfig
mkdir -p ~/.kube/
# Copy kubeconfig file
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
# Set correct permissions
sudo chmod 600 ~/.kube/config
# Configure KUBECONFIG environment variable for the current session
export KUBECONFIG=~/.kube/config
# Add KUBECONFIG to .bashrc for permanent use
echo "export KUBECONFIG=~/.kube/config" >> ~/.bashrc
# Apply .bashrc changes
source ~/.bashrc
4. Installing kubectl
kubectl is a command-line utility for managing Kubernetes clusters. K3s does not install kubectl in PATH by default, so it needs to be installed separately or a symbolic link created.
# Create a symbolic link to k3s kubectl
sudo ln -s /usr/local/bin/k3s /usr/local/bin/kubectl
Now you can use kubectl to interact with the cluster.
5. Checking Cluster Health
Ensure that the cluster sees the node and all system pods are running.
# Check node status
kubectl get nodes
# Check status of system pods in kube-system namespace
kubectl get pods -n kube-system
You should see one node with Ready status and all pods in kube-system with Running status.
6. Retrieving K3s Token (for adding agents, if needed)
If you decide to add other nodes to the K3s cluster in the future, you will need the token that was generated during installation.
# Get K3s token
sudo cat /var/lib/rancher/k3s/server/node-token
Save this token in a secure location. It will be needed to join new worker nodes to your K3s cluster.