Add K3s agent setup with NVMe-backed persistent storage
Bind-mount K3s agent data, node identity, and kubelet dirs from NVMe so container image cache and node registration survive reboots on the diskless netboot nodes. Includes K3s binary download, agent systemd service, DHCP hostname resolution, and open-iscsi for Longhorn iSCSI support.
This commit is contained in:
@@ -130,7 +130,8 @@ apt-get install -y \
|
||||
conntrack \
|
||||
socat \
|
||||
ethtool \
|
||||
nfs-common
|
||||
nfs-common \
|
||||
open-iscsi
|
||||
|
||||
# Container runtime prerequisites
|
||||
apt-get install -y \
|
||||
@@ -156,8 +157,9 @@ rm -rf /var/lib/apt/lists/*
|
||||
rm -rf /tmp/*
|
||||
rm -rf /var/tmp/*
|
||||
|
||||
# Configure hostname (will be overridden by netplan)
|
||||
echo "k3s-node" > /etc/hostname
|
||||
# Don't set static hostname - let DHCP provide it via networkd
|
||||
# Empty /etc/hostname allows transient hostname from DHCP
|
||||
echo "" > /etc/hostname
|
||||
|
||||
# Configure network with netplan
|
||||
cat > /etc/netplan/01-netcfg.yaml <<EOF
|
||||
@@ -284,6 +286,34 @@ mkdir -p "$BUILD_DIR/rootfs/etc/systemd/system/multi-user.target.wants"
|
||||
ln -sf /etc/systemd/system/setup-node-storage.service \
|
||||
"$BUILD_DIR/rootfs/etc/systemd/system/multi-user.target.wants/setup-node-storage.service"
|
||||
|
||||
# Install DHCP hostname service
|
||||
echo "Installing DHCP hostname service..."
|
||||
cp "$FILES_DIR/set-hostname-from-dhcp" "$BUILD_DIR/rootfs/usr/local/bin/"
|
||||
chmod +x "$BUILD_DIR/rootfs/usr/local/bin/set-hostname-from-dhcp"
|
||||
cp "$FILES_DIR/set-hostname-from-dhcp.service" "$BUILD_DIR/rootfs/etc/systemd/system/"
|
||||
ln -sf /etc/systemd/system/set-hostname-from-dhcp.service \
|
||||
"$BUILD_DIR/rootfs/etc/systemd/system/multi-user.target.wants/set-hostname-from-dhcp.service"
|
||||
|
||||
# Download and install K3s binary
|
||||
echo "Downloading K3s binary..."
|
||||
K3S_VERSION="v1.34.3+k3s1"
|
||||
curl -sfL "https://github.com/k3s-io/k3s/releases/download/${K3S_VERSION}/k3s" \
|
||||
-o "$BUILD_DIR/rootfs/usr/local/bin/k3s"
|
||||
chmod +x "$BUILD_DIR/rootfs/usr/local/bin/k3s"
|
||||
echo "K3s $K3S_VERSION installed"
|
||||
|
||||
# Install K3s agent service
|
||||
echo "Installing K3s agent service..."
|
||||
# Create K3s directories first (will be bind-mounted from NVMe at runtime)
|
||||
mkdir -p "$BUILD_DIR/rootfs/etc/rancher/k3s"
|
||||
mkdir -p "$BUILD_DIR/rootfs/etc/rancher/node"
|
||||
mkdir -p "$BUILD_DIR/rootfs/var/lib/rancher/k3s/agent"
|
||||
cp "$FILES_DIR/k3s-agent.service" "$BUILD_DIR/rootfs/etc/systemd/system/"
|
||||
cp "$FILES_DIR/k3s-agent.env" "$BUILD_DIR/rootfs/etc/rancher/k3s/"
|
||||
# Enable the service
|
||||
ln -sf /etc/systemd/system/k3s-agent.service \
|
||||
"$BUILD_DIR/rootfs/etc/systemd/system/multi-user.target.wants/k3s-agent.service"
|
||||
|
||||
# Build initramfs while /proc/sys/dev are still mounted
|
||||
echo "Building custom netboot initramfs..."
|
||||
KERNEL_VERSION=$(ls -1 $BUILD_DIR/rootfs/boot/vmlinuz-* | sed 's|.*/vmlinuz-||' | head -1)
|
||||
|
||||
Reference in New Issue
Block a user