Writing · kubernetes
A cheap, powerful Kubernetes cluster on Hetzner: €5 cloud control plane, auction metal worker, Talos
By Mattias Hemmingsson · · 10 min read
My small Kubernetes node for internal services ran out of memory. It was a 4 GB cloud server, and the kernel had started killing Prometheus and ArgoCD. I needed much more RAM, but cloud RAM is expensive.
So I rebuilt it as two servers on Hetzner:
- a control plane on the smallest cloud server, about €5 a month
- a worker on a metal server from the server auction, about €40 a month: 12 cores, 125 GB RAM, two 2 TB disks
Both run Talos Linux and talk to each other over a Hetzner vSwitch. Total is about €45 a month for a cluster with more memory than I will fill for a long time.
Here is how it fits together and how I installed it. I ran it with Talos v1.14 and Kubernetes v1.37. All IP addresses in this post are example addresses.
Why split it this way
- Metal RAM is five to ten times cheaper than cloud RAM. The auction box costs about what a 16 GB cloud server does.
- The control plane survives the metal box. If the worker dies or I replace it, etcd and the API are still there. I rescue or swap the worker and it joins again.
- The control plane needs very little. etcd and the API server for one worker fit in 4 GB. Workloads never run there.
- No load balancer to pay for. The worker's public IP is the cluster's front door. The ingress controller listens on ports 80 and 443 on the host, and a wildcard DNS record points at that IP.
How it is connected
Three things in this picture matter later:
- The cluster endpoint is the control plane's private address. The worker joins over the vSwitch, never over the internet.
- The metal server has one network card. The public IP comes untagged by DHCP, and the private network is a tagged VLAN on the same card.
- A vSwitch carries packets of at most 1400 bytes. The pod network has to know that.
What you need
- A Hetzner Cloud project with the small server in it (mine came with Ubuntu, which gets overwritten).
- A metal server in Hetzner Robot, in a location in the same network zone as the cloud server.
talosctlmatching the Talos version,kubectlandhelmon your laptop.- An SSH key registered in both places. The Cloud Console and Robot have separate key lists. I lost time here: my key was only in the cloud project, and rescue on the metal server refused it.
1. Network and firewall
In Robot, create a vSwitch, give it a VLAN ID (I use 4001) and add the metal server to it.
In the Cloud Console, create a private network 172.16.0.0/16 with two subnets:
- a cloud subnet
172.16.0.0/24, and attach the cloud server to it with172.16.0.2 - a vSwitch subnet
172.16.1.0/24, connected to the vSwitch you just made
Then create a cloud firewall and apply it to the control plane before you install anything: allow TCP 22, 6443 and 50000 from your own IP only. A fresh Talos node waits in maintenance mode on port 50000 and accepts a config from anyone who can reach it, so close the port first.
2. Control plane: rescue mode and dd
Talos has no installer you run from another Linux. You write a disk image straight onto the disk.
Talos builds the images for you at factory.talos.dev. Choose your version and platform and you get a schematic ID. The one below is the plain image with no extensions.
In the Cloud Console, open the server, go to Rescue, enable the Linux rescue system with your SSH key and power cycle the server. Then log in and write the image:
ssh root@203.0.113.10
S=376567988ad370138ad8b2698212367b8edcb69b5fd68c80be1f2ec7d603b4ba
curl -fsSL https://factory.talos.dev/image/$S/v1.14.7/hcloud-amd64.raw.xz \
| xz -d | dd of=/dev/sda bs=4M conv=fsync
sync
reboot
This erases the server. Note that the cloud image is the hcloud one. It reads the server's network settings from Hetzner's metadata service, so the private interface comes up by itself.
After the reboot, SSH is gone. That is correct: Talos has no shell. Check that it is waiting for you instead:
talosctl -n 203.0.113.10 get disks --insecure
3. Worker: rescue mode and dd on metal
In Robot, open the server, go to Rescue, activate the Linux rescue system with your key, then go to Reset and send an automatic hardware reset. Log in and look at what you have before you destroy it:
ssh root@198.51.100.20
lsblk -o NAME,SIZE,FSTYPE,PARTLABEL
ls -l /dev/disk/by-id | grep -v part # stable names for the disks
ip -br link # the MAC of the network card
[ -d /sys/firmware/efi ] && echo UEFI || echo BIOS
Write down the disk IDs and the MAC address. You need them for the machine config.
Then wipe the disks and write the metal image to one of them. Use the by-id path, not /dev/sda:
wipefs -a /dev/sda /dev/sdb
S=376567988ad370138ad8b2698212367b8edcb69b5fd68c80be1f2ec7d603b4ba
curl -fsSL https://factory.talos.dev/image/$S/v1.14.7/metal-amd64.raw.zst \
| zstd -d | dd of=/dev/disk/by-id/ata-YOUR_DISK_ID bs=4M conv=fsync
sync
I use no RAID. Talos lives on the first disk and the second disk is left whole for storage.
The UEFI boot entry
My server boots with UEFI, and its boot list only had the two network boot entries. With nothing pointing at the disk, it would not have started Talos. I added an entry and put it after the network entries, so Hetzner's rescue system, which boots from the network, still works:
efibootmgr -c -d /dev/sda -p 1 -L Talos -l '\EFI\BOOT\BOOTX64.EFI'
efibootmgr # read the new entry's number
efibootmgr -o 0006,0007,0008 # network entries first, then Talos
reboot
The numbers are from my server. Yours will differ.
When it comes back, ask Talos what it calls the hardware. The names are not the same as in rescue:
talosctl -n 198.51.100.20 get disks --insecure
talosctl -n 198.51.100.20 get links --insecure
On my server rescue called the Talos disk sda and Talos called it sdb. This is why the config below selects disks by WWID and never by path.
4. The machine config
Generate the secrets once and keep them out of git:
talosctl gen secrets -o secrets.yaml
Since Talos 1.12 the config is many small documents instead of one big machine: block. If you have patches from an older cluster, they will not apply. I use three patch files.
common.yaml, for both nodes. The kubelet must register with its private address, not the public one:
apiVersion: v1alpha1
kind: KubeNodeConfig
nodeIP:
validSubnets:
- 172.16.0.0/16
controlplane.yaml. etcd stays on the private network, the API certificate also covers the public IP so I can use kubectl from home, and Flannel and kube-proxy are turned off because Cilium replaces both:
machine:
certSANs:
- 203.0.113.10
- 172.16.0.2
cluster:
etcd:
advertisedSubnets:
- 172.16.0.0/16
---
apiVersion: v1alpha1
kind: HostnameConfig
auto: off
hostname: cp-1
---
apiVersion: v1alpha1
kind: KubeAPIServerConfig
certExtraSANs:
- 203.0.113.10
---
apiVersion: v1alpha1
kind: KubeFlannelCNIConfig
$patch: delete
---
apiVersion: v1alpha1
kind: KubeProxyConfig
enabled: false
worker.yaml. This is where the vSwitch is set up:
apiVersion: v1alpha1
kind: HostnameConfig
auto: off
hostname: node-1
---
# Install disk by WWID, because sda/sdb change between boots.
apiVersion: v1alpha1
kind: UnattendedInstallConfig
provisioning:
diskSelector:
match: disk.wwid == "naa.YOUR_DISK_WWID"
wipe: false
---
# Public IP: Hetzner hands it out by DHCP on the untagged network.
apiVersion: v1alpha1
kind: DHCPv4Config
name: enp35s0
---
# Private network: a tagged VLAN on the same card.
apiVersion: v1alpha1
kind: VLANConfig
name: enp35s0.4001
vlanID: 4001
parent: enp35s0
mtu: 1400
addresses:
- address: 172.16.1.2/24
routes:
- destination: 172.16.0.0/16
gateway: 172.16.1.1
The route is the part that is easy to miss. The worker's VLAN only reaches 172.16.1.0/24 directly. To reach the control plane in the cloud subnet it has to go through Hetzner's gateway, which is always the first address of the vSwitch subnet.
Now build the two configs. The endpoint is the control plane's private IP:
talosctl gen config my-cluster https://172.16.0.2:6443 \
--with-secrets secrets.yaml --install-disk /dev/sda \
--additional-sans 203.0.113.10 \
--config-patch @common.yaml --config-patch-control-plane @controlplane.yaml \
-t controlplane -o controlplane-full.yaml
talosctl gen config my-cluster https://172.16.0.2:6443 \
--with-secrets secrets.yaml \
--config-patch @common.yaml --config-patch-worker @worker.yaml \
-t worker -o worker-full.yaml
talosctl validate -c controlplane-full.yaml --mode cloud
talosctl validate -c worker-full.yaml --mode metal
5. Start the cluster
Control plane first:
talosctl apply-config --insecure -n 203.0.113.10 -f controlplane-full.yaml
talosctl config endpoint 203.0.113.10
talosctl config node 203.0.113.10
talosctl bootstrap
talosctl kubeconfig ./kubeconfig
The kubeconfig points at the private endpoint. Change the server line to the public IP so it works from your laptop.
Then the worker:
talosctl apply-config --insecure -n 198.51.100.20 -f worker-full.yaml
talosctl -n 198.51.100.20 -e 198.51.100.20 get addresses
talosctl -n 198.51.100.20 -e 198.51.100.20 get routes
You should see 172.16.1.2 on the VLAN interface and the route to 172.16.0.0/16. A minute later the worker shows up in kubectl get nodes. Both nodes stay NotReady until there is a pod network.
6. Cilium
I run Cilium without kube-proxy. Two settings matter on this setup:
ipam:
mode: kubernetes
kubeProxyReplacement: true
# Talos runs a local API proxy (KubePrism) on every node.
k8sServiceHost: localhost
k8sServicePort: 7445
# The vSwitch limit. Cilium would otherwise pick 1500 from the public card.
MTU: 1400
routingMode: tunnel
tunnelProtocol: vxlan
cgroup:
autoMount:
enabled: false
hostRoot: /sys/fs/cgroup
securityContext:
capabilities:
ciliumAgent: [CHOWN, KILL, NET_ADMIN, NET_RAW, IPC_LOCK, SYS_ADMIN, SYS_RESOURCE, DAC_OVERRIDE, FOWNER, SETGID, SETUID]
cleanCiliumState: [NET_ADMIN, SYS_ADMIN, SYS_RESOURCE]
helm repo add cilium https://helm.cilium.io/
helm install cilium cilium/cilium -n kube-system -f cilium-values.yaml
Pointing Cilium at localhost:7445 means it never needs a working service network to find the API. With MTU: 1400 the tunnel overhead is taken off that number, and large packets between the nodes stop disappearing.
7. Check it
kubectl get nodes -o wide
Both nodes should be Ready, with 172.16.0.2 and 172.16.1.2 as internal IPs. If one shows a public IP, the validSubnets patch did not apply.
Two more tests that catch real problems:
- Start a pod on the worker and ping a pod on the control plane with a large packet that may not be split:
ping -M do -s 1300 <pod ip>. If small pings work and this one does not, the MTU is wrong. - From a pod on the worker, run
curl ifconfig.me. It should print the worker's public IP.
The traps, in one table
| Trap | Why | Fix |
|---|---|---|
| Rescue on the metal server refused my SSH key | Robot and the Cloud Console keep separate key lists | Add the key in Robot too |
| No boot entry for the disk after dd | UEFI boot list had only network entries | Add a boot entry with efibootmgr, after the network ones |
| The disk I wrote Talos to had another name after the reboot | sda and sdb swap between rescue and Talos |
Select disks by WWID |
| Config patches from my older Talos cluster do not fit | Talos now uses many small config documents | Read the docs for your version, then write new patches |
| The worker cannot reach the control plane without a route | The VLAN only reaches its own subnet | Route the whole private network through the first address of the vSwitch subnet |
| Large packets between nodes get dropped at the default MTU | vSwitch packets are limited to 1400 bytes | Set mtu: 1400 on the VLAN and MTU: 1400 in Cilium |
talosctl upgrade on the worker installed but did not restart it |
Talking straight to a worker, Talos cannot drain the node | Run talosctl reboot yourself afterwards |
What I put on top
The cluster is empty at this point. What I added afterwards, all through ArgoCD:
- Traefik as a DaemonSet on the worker, listening on host ports 80 and 443. A wildcard DNS record points at the worker's public IP.
- cert-manager for Let's Encrypt certificates.
- Longhorn on the second 2 TB disk. This needs a Talos image with the
iscsi-toolsandutil-linux-toolsextensions, which is a second schematic from the image factory, and the disk declared as a Talos user volume. - CloudNativePG and a MySQL operator for databases.
After all of that the worker uses 2% of its memory.
Is it worth it
For about €45 a month I have 12 cores, 125 GB of RAM and 4 TB of disk (two 2 TB disks) in a real Kubernetes cluster, with a control plane that is separate from the hardware doing the work.
It is not highly available. There is one control plane node and one worker, so a hardware fault on the worker takes the workloads down until it is fixed. For internal tools and side projects I accept that. If I need more, a second auction server joins the same vSwitch with the same worker config and a new IP.
Filed underkubernetes · talos · hetzner · cilium · homelab · devops