
Kubernetes, part 5: cluster of multiple nodes on k3s with etcd, Longhorn, Ingress, and HTTPS via cert-manager
🌐 Machine-translated from Russian. Show original
In this part:
- Cluster diagram
- Ports between nodes
- API Permanent Address
- Step 1. First server
- Step 2. Other servers
- Step 3. Working nodes
- Step 4. Snapshots etcd
- Step 5. Longhorn Distributed Storage
- Step 6. Traffic entry into the cluster
- Step 7. cert-manager and HTTPS from Let's Encrypt
- Step 8. Application Fault Tolerance
- But what about kubeadm?
- Cluster update
Cluster diagram#
| Node | Role | IP |
|---|---|---|
| K8S-S1, K8S-S2, K8S-S3 | Server: Control Plane + etcd (can also run applications) | 192.168.1.41–43 |
| K8S-A1, K8S-A2 | Agent: only applications | 192.168.1.51–52 |
k8s-api.corp.local | a permanent API address | a virtual IP or a |
Why three servers: etcd stores the cluster state and requires quorum — most nodes. Of three, one may fail, of two — none (two are worse than one). The number of servers is always odd.
Requirements for each node: Ubuntu 24.04, unique name, synchronized time (timedatectl), network with low server latency. A fast SSD is needed for etcd — on slow disks, the cluster is unstable.
Servers are conveniently maintained as virtual machines on different physical hosts — otherwise, failure of one hypervisor will drop the quorum. How to prepare VMs — the "Linux server and KVM" series.
Ports between nodes#
| Port | Protocol | Who → to whom | Why |
|---|---|---|---|
| 6443 | TCP | all → servers | Kubernetes API and node registration |
| 2379–2380 | TCP | server ↔ | etcd |
| 8472 | UDP | all ↔ | Flannel Pod Network (VXLAN) |
| 10250 | TCP | everything ↔ | kubelet: logs, exec, metrics, |
| 80, 443 | TCP | clients → nodes | Ingress (Traefik) |
# на каждом узле, если ufw включен
sudo ufw allow from 192.168.1.0/24 to any port 6443,10250 proto tcp
sudo ufw allow from 192.168.1.0/24 to any port 2379:2380 proto tcp
sudo ufw allow from 192.168.1.0/24 to any port 8472 proto udp
sudo ufw allow from 10.42.0.0/16 to any
sudo ufw allow from 10.43.0.0/16 to any
API Permanent Address#
Nodes and kubectl need an address that does not depend on a single server. Options:
- kube-vip or keepalived — a virtual IP that "migrates" to a live server;
- HAProxy / nginx on a separate pair of machines — TCP 6443 balancing across three servers;
- A DNS record with three addresses is the simplest, but clients do not always switch correctly.
Details — see the "Cluster Load Balancer" section of the docs.k3s.io documentation. In the example below, the k8s-api.corp.local points to such an address.
Step 1. First server#
Come up with a common secret token and save it in the password manager:
export K3S_TOKEN="$(openssl rand -hex 32)"
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.37.2+k3s1" sh -s - server \
--cluster-init \
--tls-san=k8s-api.corp.local
--cluster-init includes the built-in etcd instead of SQLite. --tls-san adds the balancer name to the API certificate.
Step 2. Other servers#
On k8s-s2 and k8s-s3 (same token, same version):
export K3S_TOKEN="тот-же-токен"
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.37.2+k3s1" sh -s - server \
--server https://192.168.1.41:6443 \
--tls-san=k8s-api.corp.local
Step 3. Working nodes#
export K3S_TOKEN="тот-же-токен"
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.37.2+k3s1" sh -s - agent \
--server https://k8s-api.corp.local:6443
Check from any server or from your PC (specify https://k8s-api.corp.local:6443in kubeconfig):
kubectl get nodes -o wide
# 3 узла control-plane,etcd и 2 рабочих — все Ready
To prevent applications from consuming server resources, you can put a "taint" on them: --node-taint CriticalAddonsOnly=true:NoExecute during installation. In a small cluster, servers usually also launch applications — this is normal.
Step 4. Snapshots etcd#
K3s takes ETCD shots twice a day and stores the last 5 — in /var/lib/rancher/k3s/server/db/snapshots. Handheld shot before update:
sudo k3s etcd-snapshot save --name before-upgrade
sudo k3s etcd-snapshot ls
Copy snapshots outside the cluster (k3s can send them to S3-compatible storage — parameters --etcd-s3*). Store the token along with the snapshot — recovery is impossible without it. For backing up objects and volumes at the application level, there is Velero.
Step 5. Longhorn Distributed Storage#
Longhorn is an open block storage for Kubernetes from the creators of k3s: each volume is stored in multiple copies on different nodes, capable of snapshots and backup in S3/NFS.
At each node:
sudo apt install -y open-iscsi nfs-common
sudo systemctl enable --now iscsid
helm repo add longhorn https://charts.longhorn.io
helm repo update
helm install longhorn longhorn/longhorn -n longhorn-system --create-namespace
kubectl -n longhorn-system get pods
kubectl get storageclass # появится класс longhorn
Before installation, compare Kubernetes requirements and supported versions in the Longhorn documentation. For volumes, allocate separate disks on nodes. By default, Longhorn holds 3 copies of a volume — keep this in mind when calculating space.
Now specify storageClassName: longhorn in the PVC — and the data pod will be able to move to another node along with the volume.
Step 6. Traffic entry into the cluster#
Traefik in k3s listens to 80/443 via ServiceLB on each node. Options for directing users to it:
| Option | How |
|---|---|
| DNS to node addresses is | simple, but if the node fails, some requests go "nowhere" |
| External balancer (HAProxy, nginx, ITU or cloud balancer) | checks node health and sends traffic only to live |
| MetalLB instead of ServiceLB | issues virtual IPs to services from your network's pool — a common option for its servers |
Step 7. cert-manager and HTTPS from Let's Encrypt#
cert-manager issues and renews TLS certificates automatically. The current thread as of November 2026 is 1.21.
helm install cert-manager oci://quay.io/jetstack/charts/cert-manager \
--version v1.21.3 \
--namespace cert-manager --create-namespace \
--set crds.enabled=true
kubectl -n cert-manager get pods
Check the latest version number on cert-manager.io/docs/releases.
Certificate issuer for the entire cluster:
# cluster-issuer.yaml
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: admin@example.kz # служебный адрес вашей компании
privateKeySecretRef:
name: letsencrypt-account
solvers:
- http01:
ingress:
ingressClassName: traefik
While you are debugging it, use the https://acme-staging-v02.api.letsencrypt.org/directorytest server so you don't run into Let's Encrypt limits.
Ingress with HTTPS:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: podinfo
namespace: demo
annotations:
cert-manager.io/cluster-issuer: letsencrypt
spec:
ingressClassName: traefik
tls:
- hosts: [podinfo.example.kz]
secretName: podinfo-tls
rules:
- host: podinfo.example.kz
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: podinfo
port:
name: http
kubectl apply -f cluster-issuer.yaml -f ingress-tls.yaml
kubectl -n demo get certificate # READY = True через минуту-две
kubectl -n demo describe certificate podinfo-tls
For HTTP-01, the domain must point to the cluster, and port 80 must be accessible from the internet. For internal services (*.corp.local), use DNS-01 (if your DNS provider supports cert-manager) or your own certification authority through a publisher type CA.
Step 8. Application Fault Tolerance#
A cluster of multiple nodes will not save an application with a single replica. Minimum for important services:
replicas: 2or more, plustopologySpreadConstraintsorpodAntiAffinityso that replicas are on different nodes;- PodDisruptionBudget so that all replicas do not turn off at once during node maintenance:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: podinfo
namespace: demo
spec:
minAvailable: 1
selector:
matchLabels:
app: podinfo
- Node maintenance:
kubectl drain k8s-a1 --ignore-daemonsets --delete-emptydir-data, operation, thenkubectl uncordon k8s-a1.
But what about kubeadm?#
kubeadm assembles a "vanilla" cluster from official pkgs.k8s.io packages. You will have to choose and install the container environment (containerd), network plugin (Calico, Cilium), Ingress controller, storage, and API balancer. A good way to deeply understand Kubernetes — but for a small company, k3s (or RKE2) gives the same result with less effort.
Cluster update#
- Screenshot etcd (
k3s etcd-snapshot save). - Servers one by one: the same installation command with a new
INSTALL_K3S_VERSION, waitReady, then the next. - Worker nodes one by one:
kubectl drain→ update →kubectl uncordon.
Switch only to the next minor version, read release notes, and check that Helm charts (Longhorn, cert-manager) support the new Kubernetes version. For automation, there is a system-upgrade-controller from the k3s developers.
Comments · 0
No comments yet.Sign in to comment, rate and see all comments.