Tailscale on k3s: Exit Nodes, Subnet Routes, and ACLs
Originally published at woitzik.dev
Disclosure: This post contains Amazon affiliate links (marked with *). As an Amazon Associate I earn from qualifying purchases. Buying through them costs you nothing extra.
WireGuard on MikroTik worked, but every device needed a hand-written peer config with the right allowed IPs and DNS. Tailscale builds on WireGuard and adds NAT traversal, key distribution, and ACLs.
My tailnet runs against a self-hosted Headscale control server, and one ordinary Tailscale client running as a pod in k3s gives my phone and laptop two things: a route into the server VLAN and an exit node for mobile-data traffic. The RB5009* doesn't run Tailscale at all; it stays the firewall that enforces VLAN segmentation behind that route.
View the complete homelab infrastructure source on GitHub
Subnet Routes vs Exit Nodes
Both are features of a normal Tailscale node, and they solve different problems:
- Subnet routes let tailnet devices reach a LAN range through one node, without installing Tailscale on anything in that range. The servers on
10.0.20.0/24never see a Tailscale client; they see traffic arriving from the subnet router. Internet traffic on the remote device keeps using its normal connection. - Exit nodes route all of a device's internet traffic through the chosen node, so the device's public IP becomes the homelab's. The remote device still needs a Tailscale client and has to select the exit node; nothing on the home LAN changes.
For most homelabs, a subnet route is enough. I also run the exit node because I want mobile-data traffic to leave through my own WAN uplink.
The Router Pod
The node is a single-replica Deployment of the official tailscale/tailscale image, configured entirely through containerboot environment variables:
TS_ROUTES:10.0.20.0/24TS_HOSTNAME:homelab-routerTS_EXTRA_ARGS:--login-server=https://headscale.woitzik.dev --advertise-tags=tag:subnet-router --advertise-exit-node
The route used to be 10.0.0.0/16, which advertised every VLAN (management, DMZ, IoT, admin) to any approved tailnet device and bypassed the MikroTik's zero-trust segmentation for VPN clients. The real use case is internal services behind the Traefik VIP on the server VLAN, so the route is now scoped to that one /24.
Two details cost me time. The pod has to run privileged, not just with NET_ADMIN / NET_RAW: containerd mounts /proc/sys/net/ipv4/conf/*/src_valid_mark read-only for unprivileged pods, tailscaled can't set it, and forwarded traffic fails the reverse-path filter and is silently dropped. The visible symptom is a "subnet routing enabled but IP forwarding is disabled" health warning.
And the node state lives on a small PVC, so a pod restart doesn't register a new node.
ACLs and Auto-Approval
Headscale reads the same HuJSON policy format as Tailscale. Mine is a single-operator tailnet, so the ACL itself is short. The interesting part is who may become a router:
{
"groups": {
"group:admin": ["dw@", "david@"]
},
"tagOwners": {
"tag:subnet-router": ["group:admin"]
},
"acls": [
{
"action": "accept",
"src": ["group:admin"],
"dst": ["*:*"]
}
],
"autoApprovers": {
"routes": {
"10.0.20.0/24": ["tag:subnet-router"]
},
"exitNode": ["tag:subnet-router"]
}
}
Only group:admin can tag a node tag:subnet-router, and only a node with that tag gets its routes auto-approved. Any other node can still advertise routes, but they sit unapproved until someone approves them by hand with headscale nodes approve-routes, so a rogue or misconfigured node can't route itself into the LAN or become an exit node.
The two users in the group are the same person: logging in through OIDC created a second Headscale user (david) next to the manually created dw, and default-deny silently blocked that device until it was added.
If you add more users later, this is where least privilege starts: replace *:* with explicit destinations such as 10.0.20.0/24:443 and autogroup:internet:* for exit-node use.
NAT Traversal
The cluster sits behind two layers of NAT: the RB5009, and upstream of it a FritzBox* (a 6591 Cable) on the WAN side. Tailscale handles this without port forwarding. Clients use STUN to discover their public endpoints and try a direct WireGuard path; when no direct path is possible, traffic falls back to a DERP relay.
I don't run my own DERP server; Headscale hands clients Tailscale's public DERP map. Relayed traffic still works, just with higher latency, and tailscale status shows which path a peer is using.
The IPv6 Exit-Node Trap
--advertise-exit-node always advertises both 0.0.0.0/0 and ::/0. There is no IPv4-only exit node: advertising 0.0.0.0/0 on its own is rejected with "0.0.0.0/0 advertised without its IPv6 counterpart, please also advertise ::/0".
My k3s pod network is IPv4-only. The pod has IPv6 forwarding enabled but no global IPv6 address and no IPv6 uplink, so it advertises IPv6 exit capability it cannot deliver. The symptom on my phone was slow push notifications and app data while using the exit node.
Narrowing the route approval in Headscale didn't help, and didn't even hold, because autoApprovers.exitNode re-approved whatever the tagged node advertised on the next policy reconcile. The approval command reported success, and headscale nodes list-routes showed ::/0 approved again seconds later.
The real fix is dual-stack egress for the router pod, which I haven't built yet. If your cluster network is IPv4-only, expect the same behavior.
Two Routers, Manual Exit Choice
The router pod isn't the only node. rpi-srv-02, one of the two Raspberry Pi 4B DNS boxes, runs Tailscale natively and advertises the same three prefixes: 10.0.20.0/24, 0.0.0.0/0, and ::/0. Both nodes are approved for all three in Headscale.
For the LAN route, that overlap is Headscale's high-availability mode: when two nodes advertise the same prefix, one is primary, and if it goes offline the other serves the route.
Exit nodes work differently from the client's side. The phone uses the exit node I selected in the app. If that node goes down, its internet traffic stops until I pick the other one or turn the exit node off.
The Pi is the weaker of the two, so I tried revoking its exit-node approval and keeping it as a LAN-route-only fallback. Because of the IPv6 trap above, that left the router pod as the only exit candidate for a ::/0 it can't serve, and IPv6-first traffic on the phone hung outright instead of just being slow. I rolled it back the same day.
Dropping --advertise-exit-node from the router pod instead doesn't help either: the Pi advertises the same bundled 0.0.0.0/0 plus ::/0 pair on its own, so that wouldn't close the IPv6 gap, and all exit traffic would land on the weaker board. If I were replacing that Pi today, it would be a Raspberry Pi 5*.
Monitoring
tailscale status --json inside the router pod shows every peer, whether it's online, and its traffic counters:
tailscale status --json | jq '.Peer[] | {Name: .HostName, Online: .Online, RX: .RxBytes, TX: .TxBytes}'
On the control-plane side, headscale nodes list-routes is the ground truth for which routes are advertised, approved, and actually serving. After any routing change, check it instead of trusting the command's exit status.
The Trade-off
With Tailscale's hosted control plane, your device list, IPs, and connection metadata live on their servers. Running Headscale moves that state onto your own hardware, at the cost of operating one more service; the data plane is WireGuard either way. If you don't want a coordination server at all, plain WireGuard on MikroTik, managed with Terraform, is still the alternative.
Comments
No comments yet. Start the discussion.