Brain Phrye

code cooking diy fiction personal photos politics reviews tools 


Talos

[ Listen to article ]

The goal here was to start learning how to use talos to spin up kubernetes clusters. But first there were some yaks

I’ve been wanting to run kubernetes at home, but wasn’t too keen on having to maintain the underlying OS distros. It just seemed like an annoying distraction. Happily it seemed like the talos team agreed. However, the hard part was to get started. Cloud options cost money, can be slow and usually involve their own issues. Besides, installing on local hardware was the eventual goal. Unfortunately hardware is annoyingly slow when constantly rebooting it.

I realised the simple answer was local virtual machines. I tend to overspec my laptops with too much ram specifically so I can use VMs since I keep having to work on FreeBSD or other Linux distros. Years ago I started using libvirt and virt-manager for all my VM needs. In the pre-systemd days I had DNS working just fine.

DNS for libvirt in a systemd-resolverd world

I use the following script to configure this on any system I want to use this on. It runs as an unprivileged user (hence the sudos). It assumes a default libvirt system. The network is 192.168.122.0/24 and the bridge is virbr0. If you’ve changed that (why?) you’ll want to change this.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash

if [[ -f /etc/systemd/system/dns-virbr0.service ]]; then
  echo "Libvirt dns should work - look for hosts in vm"
fi

sudo tee /etc/systemd/system/dns-virbr0.service > /dev/null << 'EOF'
[Unit]
Description=Per-link DNS configuration for virbr0
BindsTo=sys-subsystem-net-devices-virbr0.device
After=sys-subsystem-net-devices-virbr0.device systemd-resolved.service

[Service]
Type=oneshot
ExecStart=/usr/bin/resolvectl dns virbr0 192.168.122.1
ExecStart=/usr/bin/resolvectl domain virbr0 '~vm'

[Install]
WantedBy=sys-subsystem-net-devices-virbr0.device
EOF
sudo systemctl daemon-reload
sudo systemctl enable dns-virbr0.service
sudo systemctl restart dns-virbr0.service

good_domain="<domain name='vm' localOnly='yes'/>"
domain="$(virsh net-dumpxml default | grep 'domain.*name=')"
if [[ "$domain" == "$good_domain" ]]; then
  echo "Run virsh net-edit default to add"
  echo "'$good_domain' under <network>"
fi

So now dns works. If I set the host name in the virtual machine I can get to it with the name.vm.

Not hugely important yet, but I eventually want to spin up a local ACME server and generally figure out how ingress works with k8s so dns working would be nice.

Edit: Added bit to tell libvirt’s dns server what domain it is serving!