skip to content
logo
Table of Contents

Getting Started with K3s

K3s is a lightweight Kubernetes distribution optimized for small-scale clusters, edge computing, and IoT devices.
Unlike full Kubernetes, K3s is faster, consumes fewer resources, and is easy to set up.

This guide covers:

  • Installing K3s on a single-node cluster
  • Deploying a simple application
  • Configuring K3s with multiple nodes

1. Why Use K3s Instead of Kubernetes?

K3s provides a fully compliant Kubernetes environment with a smaller footprint.
It eliminates heavy dependencies like etcd and replaces them with a SQLite datastore by default.

K3s vs. Kubernetes

FeatureK3sKubernetes
Size~50MB binary300MB+ components
DatabaseSQLite (default)etcd (default)
Requirements512MB RAM, 1 vCPU2GB+ RAM, 2 vCPUs
InstallationSingle commandMulti-step setup

2. Installing K3s (Single-Node Cluster)

Step 1: Install K3s

On any Linux-based machine, run:

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

Verify installation:

Terminal window
k3s --version

Step 2: Check Cluster Status

Terminal window
kubectl get nodes

K3s automatically installs kubectl, so you can use standard Kubernetes commands.


3. Deploying a Simple Application

K3s supports standard Kubernetes YAML manifests.

Step 1: Create a Deployment

Terminal window
nano app-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-app
spec:
replicas: 2
selector:
matchLabels:
app: demo
template:
metadata:
labels:
app: demo
spec:
containers: - name: demo-container
image: nginx
ports: - containerPort: 80

Step 2: Apply the Deployment

Terminal window
kubectl apply -f app-deployment.yaml

Step 3: Verify the Running Pods

Terminal window
kubectl get pods

4. Configuring K3s for Multiple Nodes

K3s can run in multi-node mode, with one node as the server (control plane) and others as agents (worker nodes).

Step 1: Get Node Token

On the master node, run:

Terminal window
cat /var/lib/rancher/k3s/server/node-token

Step 2: Join a Worker Node

On the worker node, run:

Terminal window
curl -sfL https://get.k3s.io | K3S_URL=https://<MASTER_IP>:6443 K3S_TOKEN=<NODE_TOKEN> sh -

Verify:

Terminal window
kubectl get nodes

5. Exposing Services with K3s’ Built-in Load Balancer

K3s includes Traefik as the default Ingress Controller.

Step 1: Deploy a Service

apiVersion: v1
kind: Service
metadata:
name: demo-service
spec:
selector:
app: demo
ports: - protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer

Apply:

Terminal window
kubectl apply -f demo-service.yaml

Check:

Terminal window
kubectl get svc

6. Conclusion

  • K3s is a lightweight Kubernetes distribution, ideal for edge devices and resource-limited environments.
  • Setup is quick, with a single command installation.
  • Multi-node clusters can be easily configured using tokens.
  • Built-in Traefik load balancer simplifies service exposure.

K3s provides the power of Kubernetes in a simplified, efficient package, making it a great choice for smaller deployments.