Which approach preserves cloud-init DNS settings across reboots in k3os?
0 reputation · 15 Jun 2022, 14:21 UTC
0 reputation · 15 Jun 2022, 14:21 UTC
The goal is to keep custom DNS servers supplied via cloud-init after a k3os node reboots.
During early boot, cloud-init writes the nameservers to /etc/resolv.conf, but k3os later runs a DNS reconciliation loop that regenerates /etc/resolv.conf from static files in /etc/rancher/k3os/dns, overwriting the cloud-init values unless those files are also updated.
It is unclear whether modifying the dns directory through cloud-init or disabling the reconciliation loop is a supported, version‑stable approach, and how this behavior differs between releases before and after v0.20.0.
Can cloud-init be directed to write to /etc/rancher/k3os/dns instead of /etc/resolv.conf?
Is it safe to disable the DNS reconciliation loop in k3os to retain cloud‑init DNS settings?
35275 reputation · 15 Jun 2022, 15:03 UTC
To preserve custom DNS settings across reboots in k3os, you must use cloud-init to write the nameservers directly to the /etc/rancher/k3os/dns directory rather than relying on the default /etc/resolv.conf. Because k3os employs a DNS reconciliation loop that regenerates /etc/resolv.conf from this specific directory, any changes made to the resolv file itself are transient and will be overwritten.
You can direct cloud-init to create the necessary configuration files in the writable k3os DNS path using the write_files module. This ensures that when the reconciliation loop runs, it pulls your custom values into the active /etc/resolv.conf.
#cloud-config
write_files:
- path: /etc/rancher/k3os/dns/nameservers
content: |
8.8.8.8
8.8.4.4
Disabling the Reconciliation Loop: It is generally not recommended to disable the k3os DNS reconciliation loop. This loop is a core component of the k3os node lifecycle management; disabling it may lead to inconsistent network states during cluster upgrades or node re-provisioning, and it is not a documented, version-stable configuration path.
Version Differences: While k3os has evolved (including changes around v0.20.0), the fundamental architecture of a read-only root filesystem and the use of /etc/rancher/k3os/ for persistent configuration remains the standard. Writing to the specific k3os DNS directory is the most portable method across these versions.
write_files configuration shown above.cat /etc/resolv.conf.sudo reboot.cat /etc/resolv.conf.Diagnostic Detail Needed: To provide a more precise recommendation regarding version-specific behavior, please specify the exact k3os release version currently in use.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 16 Jun 2022, 01:47 UTC
Starting with k3os v0.20.0 the DNS reconciliation loop reads /etc/rancher/k3os/dns/resolv.conf (and optionally hosts) to rebuild the active /etc/resolv.conf. Therefore a cloud‑init write_files block should target that exact path, e.g. path: /etc/rancher/k3os/dns/resolv.conf. For releases prior to v0.20.0 the loop ignored the dns directory, so persisting cloud‑init DNS required either disabling the loop (via k3os.dns=none kernel param) or adding a post‑boot script that rewrites /etc/resolv.conf after the loop runs. In both cases ensure the file is owned by root with mode 0644; otherwise the loop may skip it and fall back to defaults.