1. Getting Started with K3s - A Step-by-Step Guide to Local Setup


Kubernetes (K8s) has revolutionized the way we manage containerized applications, but its complexity can be intimidating for developers. This is where K3s shines. Lightweight, easy to install, and perfect for local development or resource-constrained environments, K3s is a stripped-down yet fully compliant Kubernetes distribution. In this guide, we’ll walk you through setting up a local K3s cluster from scratch.
What is K3s and Why Should You Use It?
K3s, developed by Rancher, is a lightweight Kubernetes distribution designed with simplicity and efficiency in mind. It requires fewer resources, making it ideal for developers who want to experiment with Kubernetes on their laptops or edge devices like Raspberry Pi.
Advantages of K3s:
Resource-Friendly: Designed for environments with limited CPU and memory.
Quick Installation: A single command gets you up and running in minutes.
Local Development: Ideal for developers who need a Kubernetes cluster for testing applications without managing full-scale K8s.
Easy Updates: Includes built-in automation for updates and patches.
Step 1: Installing K3s
Prerequisites:
A system running a modern Linux distribution (e.g., Ubuntu, CentOS, Debian).
Root or sudo access to the system.
curl
installed (you can install it usingsudo apt install curl
if it’s missing).
Installation Process
To install K3s, open your terminal and run the following command:
curl -sfL https://get.k3s.io | sh -
What this does:
Downloads the K3s binary.
Installs and configures K3s as a systemd service.
Sets up the control plane and starts the cluster.
After the installation completes, K3s automatically sets up a Kubernetes cluster.
Step 2: Accessing Your Cluster
Setting Up the Kubeconfig File
K3s creates a kubeconfig
file at /etc/rancher/k3s/k3s.yaml
by default. This file is needed to interact with the cluster using kubectl
.
To make this file accessible to your current user, export the path to the KUBECONFIG
environment variable:
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
For convenience, add this line to your shell configuration file (e.g., ~/.bashrc
or ~/.zshrc
) to persist the setting across sessions.
If you have kubectl
already installed, you can now run commands directly on your K3s cluster.
Step 3: Verifying the Installation
To ensure your K3s cluster is up and running, use the following commands:
Check Cluster Status:
kubectl get nodes
This should list your node(s) with a
STATUS
ofReady
.Verify System Pods:
kubectl get pods -A
This lists all system pods in all namespaces. Ensure that essential services like
kube-dns
are running.
Step 4: Common Issues and Troubleshooting
Problem: “kubectl: command not found”
Solution: Install kubectl
by running:
curl -LO "https://dl.k8s.io/release/$(curl -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
Problem: Node is not in “Ready” state
Solution: Check the K3s service logs using:
sudo journalctl -u k3s.service -f
Look for errors such as network issues or missing dependencies.
Problem: Network Connectivity Issues
Solution: Ensure ports like 6443
(Kubernetes API) are open and not blocked by a firewall.
Conclusion
Setting up a local K3s cluster is as simple as running a single command. Its lightweight design, combined with the full power of Kubernetes, makes it an excellent choice for development and testing. Once your cluster is running, you can deploy applications, experiment with Kubernetes concepts, and enhance your DevOps workflows—all on your local machine.
What’s Next?
Experiment with deploying a sample app to your K3s cluster.
Dive deeper into Kubernetes concepts like deployments, services, and networking.
Explore K3s features like multi-node clustering and Helm chart support.
Got stuck or have questions? Drop them in the comments below, and let’s troubleshoot together!
Subscribe to my newsletter
Read articles from Suyash Bhawsar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Suyash Bhawsar
Suyash Bhawsar
Tech enthusiast, DevOps learner. Arch Linux w/ KDE. Rust learner. Harmonium player. Sudoku solver. Passionate about music and technology.