TechBuzzPro

3 Node k3s Homelab: Testing Production Patterns

· 5 min read · Apps & Browsers

In this article
  1. Why a 3-Node k3s Cluster?
  2. Setting Up the Cluster
  3. Testing Production Patterns
  4. Common Pitfalls and How to Avoid Them
  5. Comparing k3s to Other Kubernetes Distributions
  6. Costs and Resource Considerations
  7. Safety and Data Integrity
  8. Frequently Asked Questions

This article explains how a 3-node k3s cluster in a homelab is used to test production-grade Kubernetes patterns, covering what you need to set it up, how to use it for validating deployments, and the key differences from a real production environment. You will learn the practical steps, common pitfalls, and how to make the most of this setup for learning and experimentation.

Why a 3-Node k3s Cluster?

K3s is a lightweight, certified Kubernetes distribution designed for resource-constrained environments, making it ideal for homelabs. A 3-node cluster (one server, two agents) provides a realistic environment to test patterns that require multiple nodes, such as pod anti-affinity, distributed storage, and rolling updates with zero downtime. Unlike a single-node setup, a 3-node cluster lets you simulate node failures and observe how Kubernetes reschedules workloads, which is essential for validating high-availability patterns.

Setting Up the Cluster

To start, you need three machines (physical or virtual) with at least 2 CPU cores and 4 GB RAM each. Install k3s on the first node as the server using curl -sfL https://get.k3s.io | sh -. Then, on the other two nodes, install as agents by setting the K3S_URL and K3S_TOKEN environment variables (the token is found at /var/lib/rancher/k3s/server/node-token on the server). After installation, verify the cluster with kubectl get nodes — you should see three nodes in Ready state.

Testing Production Patterns

Once the cluster is up, you can test patterns like:

  • Deployments with rolling updates: Use kubectl rollout status deployment/my-app to watch updates without downtime.
  • Services and Ingress: Expose apps via a LoadBalancer service (k3s includes a built-in load balancer) or an Ingress controller like Traefik (pre-installed).
  • Persistent volumes: Use local-path-provisioner (default in k3s) to test PVCs, or install a distributed storage solution like Longhorn for cross-node persistence.
  • Pod anti-affinity: Deploy replicas with podAntiAffinity to ensure they spread across nodes, simulating a production topology.
  • ConfigMaps and Secrets: Manage configuration and sensitive data, and test mounting them into pods.
  • Network policies: Use a CNI plugin like Cilium (k3s supports it) to enforce network segmentation.

Common Pitfalls and How to Avoid Them

One common mistake is assuming k3s behaves exactly like a full Kubernetes cluster. For example, k3s uses SQLite instead of etcd for its datastore by default (though it supports etcd for HA), which can affect performance under heavy load. Also, the default Traefik ingress may not support all annotations you use in production. To avoid issues, always test your actual manifests in a staging environment before relying on the homelab results. Another pitfall is resource exhaustion: with only 4 GB RAM per node, running memory-hungry workloads can cause OOM kills. Monitor with kubectl top nodes and adjust requests/limits accordingly.

Comparing k3s to Other Kubernetes Distributions

K3s is often compared to MicroK8s (Canonical) and K0s (k0sproject). MicroK8s is similar but includes add-ons like Istio and Knative out of the box, while K0s focuses on simplicity and supports HA out of the box. K3s stands out for its small binary size and low resource usage, making it perfect for Raspberry Pi clusters or small VMs. However, for testing patterns that rely on etcd (e.g., leader election with Lease objects), you might want to enable etcd in k3s via the --cluster-init flag on the server node, which also provides HA for the control plane.

Costs and Resource Considerations

The main cost is hardware: three machines or VMs. If you already have a hypervisor like Proxmox or VMware, you can run three VMs on a single host, but that defeats the purpose of testing node failures (since they share the same physical resources). For a true homelab, consider using three Raspberry Pi 4s (8 GB) or repurposed mini PCs. Electricity and cooling are minor but not negligible. Software costs are zero since k3s is open-source. Time is the biggest investment: learning Kubernetes and debugging issues.

Safety and Data Integrity

Since a homelab is often used for personal projects, data loss is not catastrophic, but it's still good practice to back up critical data. Use k3s etcd snapshots (if using etcd) or backup your PVs manually. Also, secure your cluster by enabling TLS, using strong passwords, and not exposing the API server to the internet unless necessary. If you do expose it, use authentication and network policies.

Frequently Asked Questions

Can I use a 3-node k3s cluster for production?

Technically yes, but it's not recommended for critical workloads due to lack of support and hardening. K3s is production-ready for edge deployments, but a homelab setup often lacks proper monitoring, backup, and security practices. Use it for testing and learning, not for serving real users.

How do I enable HA for the control plane in k3s?

Run the server node with --cluster-init and then add additional server nodes (not agents) with the same token and --server https://<first-server-ip>:6443. This uses etcd for storage, providing high availability. You need at least three server nodes for a quorum.

What is the difference between k3s and k8s?

K3s is a lightweight Kubernetes distribution that packages Kubernetes into a single binary, uses SQLite or etcd, and includes Traefik and local-path-provisioner by default. It is CNCF-certified and passes the same conformance tests as standard Kubernetes, but it removes some optional features and uses less memory.

How do I test node failure in my homelab?

Simply shut down one of the agent nodes (e.g., sudo shutdown -h now) and observe how your workloads are rescheduled. With a deployment of 3 replicas and pod anti-affinity, you'll see the pod on the failed node get recreated on another node. This tests your readiness probes and eviction policies.

Can I run stateful applications like databases on k3s?

Yes, but you need persistent storage. Use the local-path-provisioner for single-node persistence, or install Longhorn for replicated storage across nodes. Test your backup and restore procedures regularly, as database data is critical.

Is k3s suitable for running Windows containers?

No, k3s only supports Linux containers. For Windows containers, you would need a full Kubernetes cluster with Windows worker nodes, which is not supported by k3s.