Skip to content

K3s HA cluster basics

A complete reference guide for understanding and setting up a K3s HA cluster


1. What is K3s HA Cluster

K3s is a lightweight Kubernetes distribution. HA (High Availability) mode uses embedded etcd to distribute cluster state across multiple control-plane nodes, ensuring the cluster survives node failures.

root@NUC-B:/home/castis# kubectl get nodes
NAME             STATUS     ROLES                       AGE    VERSION
castis-desktop   NotReady   control-plane,etcd,master   262d   v1.33.3+k3s1
nuc-a            Ready      control-plane,etcd,master   262d   v1.33.3+k3s1
nuc-b            Ready      control-plane,etcd,master   262d   v1.34.5+k3s1

2. Node Roles Explained

Role Meaning
control-plane Manages the entire cluster — runs apiserver, scheduler, controller
etcd Hosts a member of the distributed etcd database
master Legacy alias for control-plane — same meaning, kept for backwards compatibility

3. etcd and Quorum

What is Quorum?

Quorum is the minimum number of nodes that must agree before any cluster change is committed. etcd uses the Raft consensus algorithm which requires a majority vote.

Quorum = (N / 2) + 1   (rounded down)

Quorum Table

Total Nodes Quorum Needed Failures Tolerated
1 1 0
2 2 0
3 2 **1 **
4 3 1
5 3 **2 **
7 4 **3 **

Why Odd Numbers?

Even numbers give no extra fault tolerance but cost more nodes:

3 nodes → tolerate 1 failure
4 nodes → tolerate 1 failure  ← same as 3! wasted a node
5 nodes → tolerate 2 failures
6 nodes → tolerate 2 failures  ← same as 5! wasted a node

Rule: Always use odd numbers for etcd members

Quorum Analogy

etcd = a voting committee
       majority must agree before any decision is made

3 nodes:
  nuc-a          votes YES 
  nuc-b          votes YES 
  castis-desktop OFFLINE  

Result: 2/3 = majority → cluster stays healthy 

7 Node Quorum Example

Total   Dead    Alive   Quorum  Status
──────────────────────────────────────
  7       0       7       4      Healthy
  7       1       6       4      Healthy
  7       2       5       4      Healthy
  7       3       4       4      Healthy (last safe state)
  7       4       3       4      FROZEN
  7       5       2       4      FROZEN
Minimum HA    →  3 nodes  (tolerate 1 failure)
Production    →  5 nodes  (tolerate 2 failures)
Critical      →  7 nodes  (tolerate 3 failures)

Beyond 7 etcd members is not recommended — more members means more network chatter per write, which slows the cluster.


4. Control-Plane Components

The control-plane is the brain of the cluster. It is made of 4 components:

kube-apiserver — The Gateway

Every command goes through here

kubectl apply → apiserver → writes to etcd
kubectl get   → apiserver → reads from etcd

Nothing talks to etcd directly except the apiserver

kube-scheduler — The Placement Decider

"A new pod needs to run somewhere..."

Looks at:
  - which nodes have enough CPU/RAM
  - node labels and taints
  - pod affinity rules

Decides: "Put this pod on nuc-b"
Then writes decision → apiserver → etcd

kube-controller-manager — The Watchdog

Constantly watches etcd desired state vs real state

Example:
  etcd says:  "I want 3 replicas of my-app"
  reality:    "only 2 are running"
  action:     "create 1 more pod"

Other controllers:
  - Node controller     (detects node failures)
  - Job controller      (runs batch jobs)
  - Endpoint controller (updates service endpoints)

cloud-controller-manager — Cloud Integration

Only relevant for AWS, GCP, Azure etc.
Manages cloud-specific resources (load balancers, volumes)
NOT present in bare-metal k3s setup

How They Work Together

kubectl apply -f deployment.yaml
      │
      ▼
kube-apiserver    → validates and stores in etcd
      │
      ▼
etcd              → stores "deployment my-app created"
      │
      ▼
controller-manager → sees "deployment needs 3 pods"
                     creates 3 pod objects in etcd
      │
      ▼
kube-scheduler    → sees "3 pods have no node assigned"
                    assigns each pod to a node
                    writes back to etcd
      │
      ▼
kubelet           → sees "I have a pod assigned to me"
(on worker node)    actually starts the container

Restaurant Analogy

etcd               = the order book  (stores all orders)
apiserver          = the cashier     (takes all requests)
scheduler          = the manager     (assigns orders to chefs)
controller-manager = the supervisor  (ensures orders get fulfilled)
worker node        = the kitchen     (does the actual cooking)

5. What etcd Stores

etcd is a key-value database that stores only cluster definitions and state — never actual application data.

Storage Path Format

/registry/<resource-type>/<namespace>/<name>  →  value (JSON/protobuf)

Exact Data Stored

Category Examples
Workloads pods, deployments, replicasets, statefulsets, daemonsets, jobs, cronjobs
Configuration configmaps, secrets (base64), namespaces
Networking services, endpoints, ingresses, networkpolicies
Storage PV definitions, PVCs, storageclasses
Node Info node status, capacity, conditions, labels, taints
RBAC roles, rolebindings, clusterroles, serviceaccounts
Scheduling priorityclasses, PodDisruptionBudgets, HPA
Leases active scheduler, active controller, node heartbeats

What etcd Does NOT Store

  actual container images
  actual application data (database files, uploads)
  PV data (actual file contents)
  container logs
  metrics/monitoring data

etcd Size in Reality

Small cluster  (3 nodes)   :   50-200 MB
Medium cluster (100 nodes) :   500 MB - 2 GB
Large cluster  (1000 nodes):   4-8 GB  ← keep under 8 GB

Key insight: etcd only stores definitions and state — this is why it stays small even in large clusters.


6. Control-Plane vs Worker Node

The Clear Separation

Control-plane  =  the BRAIN   →  thinks and decides
Worker node    =  the MUSCLE  →  actually does the work
┌─────────────────────────────────────────┐
│           CONTROL PLANE                 │
│                                         │
│  etcd        ← remembers everything     │
│  apiserver   ← receives all commands    │
│  scheduler   ← decides WHERE to run     │
│  controller  ← watches and fixes state  │
│                                         │
│   does NOT run your actual workloads  │
└──────────────────┬──────────────────────┘
                   │ "run this on worker"
                   ▼
┌─────────────────────────────────────────┐
│             WORKER NODE                 │
│                                         │
│  kubelet     ← receives instructions    │
│  kube-proxy  ← handles networking       │
│  container   ← YOUR actual app        │
│  container   ← YOUR database          │
│  container   ← YOUR service           │
│                                         │
│   ALL real compute happens here       │
└─────────────────────────────────────────┘

etcd vs Control-Plane vs Worker — Stacked vs Separated

Pattern Description Used In
Stacked (k3s default) control-plane + etcd on same node k3s, small clusters
External etcd control-plane and etcd on separate nodes Large production
Managed Cloud provider manages etcd separately GKE, EKS, AKS

7. Taints and Tolerations

Concept

Taint       =  a REPELLENT on a node
               "I don't want regular pods here"  

Toleration  =  a pod's PASS to ignore a taint
               "I am allowed to go there anyway"  

Analogy:

Taint       =  "No Entry" sign on a door   
Toleration  =  VIP pass to enter anyway    

Default Control-Plane Taint

node-role.kubernetes.io/control-plane:NoSchedule

key    = node-role.kubernetes.io/control-plane
effect = NoSchedule  ← "don't schedule pods here"

The 3 Taint Effects

Effect Meaning
NoSchedule New pods CANNOT be placed here. Existing pods stay.
PreferNoSchedule Scheduler tries to avoid but will use if no other choice
NoExecute New pods cannot be placed AND existing pods get EVICTED

Toleration in deployment.yaml

spec:
  template:
    spec:
      tolerations:
      - key: "node-role.kubernetes.io/control-plane"
        operator: "Exists"   # just check if key exists
        effect: "NoSchedule" # must match taint effect on node

This means: "I tolerate your NoSchedule — I acknowledge it exists but I have permission to bypass it"

Visual Flow

WITHOUT toleration:
  Pod → control-plane node
            NoSchedule 
           BLOCKED  → goes to worker node

WITH toleration:
  Pod → control-plane node
            NoSchedule 
            Pass accepted → runs on control-plane

Special Case — All Nodes are Control-Plane (Your Setup)

k3s automatically removes NoSchedule taint
when no worker nodes exist

→ Pods run freely on ALL nodes
→ No toleration needed in yaml 

8. Pod Scheduling

Default Behavior — Automatic

You do NOT need to specify which node in deployment.yaml. The scheduler decides automatically:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app
        image: nginx

Scheduler logic:

nuc-a          → has 2GB free RAM  
nuc-b          → has 4GB free RAM  
castis-desktop → has 1GB free RAM  

pod 1 → nuc-b          (most resources)
pod 2 → nuc-a
pod 3 → castis-desktop

Optional — Manual Placement

nodeSelector — Pin to specific node label

spec:
  template:
    spec:
      nodeSelector:
        kubernetes.io/hostname: nuc-b

nodeName — Hard pin to exact node

spec:
  template:
    spec:
      nodeName: nuc-a

nodeAffinity — Soft or hard preferences

spec:
  template:
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: node-role
                operator: In
                values:
                - gpu-node

Scheduling Summary

Method How Use Case
Automatic Scheduler decides Normal workloads
nodeSelector Match node label Pin to node type
nodeName Hard pin Force specific node
nodeAffinity Rules-based Complex placement
tolerations Bypass taint Run on control-plane

9. Persistent Volumes (PV)

Where PV Lives

Control-plane  →  stores PV definition only (in etcd, small)
Worker node    →  stores ACTUAL PV data (large!)

What PV Stores

Databases     →  MySQL, PostgreSQL, MongoDB data
File storage  →  uploaded files, media, documents
Logs          →  application log files
Cache         →  Redis, Elasticsearch data
Backups       →  application backups

PV Storage Types

Type Description Best For
Local Directly on worker disk Simple, single node
NFS Shared over network from NAS Small clusters
Longhorn Replicated across workers k3s production
Rook/Ceph Enterprise distributed storage Large scale
Cloud AWS EBS, GCP Disk Cloud deployments

The Problem with Local PV

Pod runs on Worker 1  →  PV is on Worker 1 disk  
Worker 1 DIES 
Pod moves to Worker 2
PV data is still on Worker 1 disk! 

Solution — Distributed Storage (Longhorn)

Worker 1  →  PV copy 1 ──┐
Worker 2  →  PV copy 2 ──┼──► replicated, any node can access
Worker 3  →  PV copy 3 ──┘

10. Hardware Specifications

Minimum Requirements

Component Control-Plane Worker Node
CPU 2 cores 1 core
RAM 2 GB 512 MB
Disk 20 GB SSD 10 GB
Network 1 Gbps 1 Gbps
Component Control-Plane Worker Node
CPU 4-8 cores 8-16 cores
RAM 8-16 GB 32-64 GB
Disk 100 GB SSD/NVMe 1 TB+
Network 1-10 Gbps 1-10 Gbps

Why Disk Speed Matters for etcd

HDD  (100 MB/s)    →  slow etcd  →  cluster feels sluggish  
SSD  (500 MB/s)    →  good etcd  →  normal performance      
NVMe (3000 MB/s)   →  fast etcd  →  excellent performance   

Common etcd warnings on slow disk:

"apply entries took too long"
"heartbeat took too long"

Disk Sizing with PV

Control-Plane:
  OS             :  20 GB
  etcd data      :  10-20 GB
  system logs    :  10 GB
  Total          :  50-100 GB SSD  ← needs speed not size

Worker Node:
  OS             :  20 GB
  container images: 20-50 GB
  PV - database  :  100 GB+
  PV - files     :  500 GB+
  PV - logs      :  100 GB+
  Total          :  500 GB - several TB  ← needs size

Sizing by Cluster Size

Cluster Size Control-Plane Worker
Small (up to 10 nodes) 4 core, 8 GB RAM, 50 GB SSD 4 core, 8 GB RAM, 500 GB
Medium (10-100 nodes) 8 core, 32 GB RAM, 100 GB NVMe 16 core, 64 GB RAM, 1 TB
Large (100+ nodes) 16 core, 64 GB RAM, 200 GB NVMe 32 core, 128 GB RAM, 2 TB+

10-Node Cluster Design

Design Control-Plane+etcd Workers Failures Tolerated Best For
3 + 7 3 7 1 node Small production
5 + 5 5 5 2 nodes Standard production
7 + 3 7 3 3 nodes Too few workers

Required Open Ports

Port Node Purpose
6443 Control-Plane kube-apiserver
2379 Control-Plane etcd client
2380 Control-Plane etcd peer communication
10250 All kubelet API
30000-32767 Worker NodePort services

11. Setting Up K3s HA Cluster

Step 1 — First Server Node (Bootstrap)

curl -sfL https://get.k3s.io | sh -s - server \
  --cluster-init \
  --tls-san <LOAD_BALANCER_IP_OR_DNS> \
  --tls-san <NODE1_IP> \
  --tls-san <NODE2_IP> \
  --tls-san <NODE3_IP>
  • --cluster-init bootstraps the embedded etcd cluster
  • --tls-san adds SANs to TLS cert for multi-node access

Get the node token:

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

Step 2 — Additional Control-Plane Nodes

curl -sfL https://get.k3s.io | sh -s - server \
  --server https://<FIRST_NODE_IP>:6443 \
  --token <NODE_TOKEN_FROM_STEP_1> \
  --tls-san <LOAD_BALANCER_IP_OR_DNS>

Step 3 — Worker Nodes (Optional)

curl -sfL https://get.k3s.io | \
  K3S_URL=https://<SERVER_IP>:6443 \
  K3S_TOKEN=<TOKEN> \
  sh -

Step 4 — Verify

kubectl get nodes

Troubleshooting NotReady Node

# Check k3s logs
journalctl -u k3s -f

# Check node conditions
kubectl describe node <node-name>

# Restart k3s
systemctl restart k3s

Quick Reference Summary

Concept One Line
etcd The database — stores all cluster state (definitions only)
apiserver The gateway — only door in and out of etcd
scheduler The placement engine — decides where pods run
controller-manager The watchdog — ensures reality matches desired state
worker node The muscle — runs all actual containers and workloads
taint Lock on a node — blocks pods from scheduling there
toleration Key/pass — allows pod to bypass a taint
PV Persistent storage — lives on worker nodes, can be large
quorum Majority vote — always use odd number of etcd members

Control-plane = manages WHAT runs and WHERE Worker node = actually RUNS it etcd = remembers EVERYTHING