88 lines
2.5 KiB
Markdown
88 lines
2.5 KiB
Markdown
---
|
|
title: "Setting Up a K3s Kubernetes Cluster"
|
|
description: "A comprehensive guide to setting up a K3s cluster for your home lab or edge environment, with high availability and persistent storage."
|
|
pubDate: "2023-11-15"
|
|
heroImage: "/blog/images/posts/k3installation.png"
|
|
category: "Kubernetes"
|
|
tags: ["kubernetes", "k3s", "homelab", "infrastructure"]
|
|
draft: false
|
|
---
|
|
|
|
# Setting Up a K3s Kubernetes Cluster
|
|
|
|
K3s is a lightweight, certified Kubernetes distribution designed for resource-constrained environments like edge devices, IoT, and home labs. This guide will walk you through setting up a production-ready K3s cluster.
|
|
|
|
## Prerequisites
|
|
|
|
- At least two machines (physical or virtual) for high availability
|
|
- Ubuntu 20.04 LTS or newer
|
|
- At least 2GB RAM per node
|
|
- 20GB+ storage per node
|
|
- Network connectivity between all nodes
|
|
|
|
## Installing the Server Node
|
|
|
|
First, let's install the primary server node:
|
|
|
|
```bash
|
|
curl -sfL https://get.k3s.io | sh -s - server \
|
|
--cluster-init \
|
|
--tls-san=server-ip-or-hostname \
|
|
--disable traefik \
|
|
--disable servicelb
|
|
```
|
|
|
|
This initializes the cluster with:
|
|
- HA enabled with `--cluster-init`
|
|
- Custom TLS SAN for API server
|
|
- Disabled default traefik ingress (we'll use Nginx)
|
|
- Disabled default ServiceLB (we'll use MetalLB)
|
|
|
|
## Installing Agent Nodes
|
|
|
|
On each worker node, run:
|
|
|
|
```bash
|
|
curl -sfL https://get.k3s.io | K3S_URL=https://server-ip:6443 K3S_TOKEN=node-token sh -
|
|
```
|
|
|
|
Replace `server-ip` with your server's IP and get the token from `/var/lib/rancher/k3s/server/node-token` on the server.
|
|
|
|
## Adding High Availability
|
|
|
|
For HA, add additional server nodes:
|
|
|
|
```bash
|
|
curl -sfL https://get.k3s.io | sh -s - server \
|
|
--server https://first-server-ip:6443 \
|
|
--token node-token \
|
|
--tls-san=this-server-ip \
|
|
--disable traefik \
|
|
--disable servicelb
|
|
```
|
|
|
|
## Setting Up Persistent Storage
|
|
|
|
We'll use Longhorn for distributed storage:
|
|
|
|
```bash
|
|
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/longhorn.yaml
|
|
```
|
|
|
|
Longhorn provides replicated block storage across your nodes for high availability.
|
|
|
|
## Next Steps
|
|
|
|
After setting up your cluster, you might want to:
|
|
|
|
1. Install a proper ingress controller (Nginx, Traefik)
|
|
2. Set up a load balancer (MetalLB)
|
|
3. Configure monitoring with Prometheus and Grafana
|
|
4. Implement GitOps with Flux or ArgoCD
|
|
|
|
Stay tuned for detailed guides on each of these topics!
|
|
|
|
---
|
|
|
|
This guide provides a starting point for your journey with K3s Kubernetes. In future posts, we'll dive deeper into advanced configurations.
|