NAME
Rex::Rancher::Node - Linux node preparation for Rancher Kubernetes distributions (RKE2/K3s)
VERSION
version 0.003
SYNOPSIS
use Rex::Rancher::Node;
# Full preparation with hostname
prepare_node(
hostname => 'worker-01',
domain => 'k8s.local',
timezone => 'Europe/Berlin',
);
# Minimal preparation — hostname left unchanged; timezone UTC and
# locale en_US.UTF-8 are still set (the defaults), chrony installed
prepare_node();
# Skip NTP (e.g. host is a VM with hypervisor time sync)
prepare_node(
hostname => 'vm-01',
domain => 'k8s.local',
ntp => 0,
);
DESCRIPTION
Rex::Rancher::Node prepares a Linux node for Rancher Kubernetes distributions (RKE2 and K3s). The same "prepare_node" call is verified on Debian, Ubuntu, and RHEL/Rocky/Alma — the supported set. openSUSE Leap / SLES is unverified: the base-package step there falls through to Rex's generic pkg abstraction (zypper) and has never been exercised on real SUSE hardware, so it is unsupported and best-effort only.
The module sets OS-level configuration that Kubernetes requires:
Swap disabled — Kubernetes does not function correctly with swap enabled.
Kernel modules —
br_netfilteris needed for iptables to see bridged traffic;overlayis required for containerd's overlay filesystem.Sysctl parameters — IP forwarding and bridge netfilter settings required by Kubernetes networking and CNI plugins.
NTP — Time skew between nodes causes certificate validation failures and etcd instability. An already synchronized clock is left as it is; otherwise
chronyis installed and started, withsystemd-timesyncdas the fallback when that install fails on a host that has it (Debian/Ubuntu). Without either, preparation goes on with a warning that no time synchronization is active.
Called automatically by "rancher_deploy_server" in Rex::Rancher and "rancher_deploy_agent" in Rex::Rancher.
prepare_node
Prepare a Linux node for Kubernetes. Performs all OS-level configuration required before installing RKE2 or K3s:
On Debian/Ubuntu, stop
unattended-upgrades,apt-daily.serviceandapt-daily-upgrade.service(they hold the apt lock on a fresh boot) and runapt-get update. They are not restarted afterwards; their timers bring them back on schedule,unattended-upgradesat the next boot.Install
curlandca-certificatesSet hostname via
hostnamectlor/etc/hostname(optional). A static hostname (/etc/hostname) that already ishostnameor whose first label ishostname, compared case-insensitively, is left as it is, whateverdomainsays:hostname => 'worker-01'keepsworker-01.example.com. The Kubernetes node name then follows the kernel hostname, that FQDN, unlessnode_nameis set ("install_server" in Rex::Rancher::Server, "install_agent" in Rex::Rancher::Agent).Add a
127.0.1.1entry to/etc/hostswhenhostnameis given:FQDN hostnamewith adomain,hostnamealone without one (then only if no line in/etc/hostsnames the host yet)Set timezone via
timedatectlor symlink (default:UTC). A timezone that is not shaped like a zoneinfo name (Area/Citysuch asEurope/BerlinorAmerica/Argentina/Buenos_Aires,UTC,Etc/GMT+5: parts of letters, digits,_,+and-, each starting with a letter, separated by/) dies before the host is touched. Whether the zone exists is left to the host.Set locale via
localectlor/etc/default/locale(default:en_US.UTF-8). On Debian/Ubuntu the locale is first enabled in/etc/locale.genand generated withlocale-gen(skipped forC/POSIXand whenlocale-genis not installed). The charset is written the waylocale.genspells it, sode_DE.utf8enablesde_DE.UTF-8 UTF-8. A locale that is notlanguage_TERRITORY.charset@modifiershaped (letters, digits,_,-) dies before the host is touched.NTP (default: enabled): nothing is installed when
timedatectlalready reports the clock as NTP-synchronized; otherwisechronyis installed and started. If thechronyinstall fails,systemd-timesyncdis started instead where the host has it (Debian/Ubuntu; the RHEL family does not ship it). When that is not active either,prepare_nodegoes on with a warning that no time synchronization is activeDisable and remove swap entries from
/etc/fstabLoad
br_netfilterandoverlaykernel modules and persist to/etc/modules-load.d/kubernetes.confWrite
/etc/sysctl.d/99-kubernetes.confwithnet.ipv4.ip_forward,net.bridge.bridge-nf-call-iptables, andnet.bridge.bridge-nf-call-ip6tables, then apply withsysctl --system
prepare_node(
hostname => 'worker-01', # optional — short hostname
domain => 'k8s.local', # optional — domain suffix for FQDN
timezone => 'Europe/Berlin', # optional, default: UTC
locale => 'en_US.UTF-8', # optional, default: en_US.UTF-8
ntp => 1, # optional, default: 1 (ensure NTP sync)
);
If hostname is provided without domain, /etc/hosts gets 127.0.1.1 hostname unless a line already names the host (e.g. the public IP the provider wrote), which is then left alone.
SEE ALSO
Rex::Rancher, Rex::Rancher::Server, Rex::Rancher::Agent, Rex
SUPPORT
Issues
Please report bugs and feature requests on GitHub at https://github.com/Getty/rex-rancher/issues.
CONTRIBUTING
Contributions are welcome! Please fork the repository and submit a pull request.
AUTHOR
Torsten Raudssus <getty@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.