Skip to content

Instantly share code, notes, and snippets.

@Alceatraz
Created November 25, 2024 06:10
Show Gist options
  • Select an option

  • Save Alceatraz/198725573730bc8ba17074e9e2c24f30 to your computer and use it in GitHub Desktop.

Select an option

Save Alceatraz/198725573730bc8ba17074e9e2c24f30 to your computer and use it in GitHub Desktop.
K3s in Debian 12 Sandbox by systemd-nspawn
debootstrap --include=dbus,systemd stable /opt/container/k3s https://mirrors4.tuna.tsinghua.edu.cn/debian/
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/vm/overcommit_memory
echo 196608 > /proc/sys/net/netfilter/nf_conntrack_max
echo 1 > /proc/sys/kernel/panic_on_oops
echo 10 > /proc/sys/kernel/panic
modprobe br_netfilter
modprobe overlay
modprobe iptable_nat
modprobe iptable_filter
systemd-run \
--collect \
--unit=k3s \
--working-directory=/opt/container/k3s \
--property=KillMode=mixed \
--property=Type=notify \
--property=Delegate=yes \
--property=TasksMax=infinity \
--property=SuccessExitStatus=133 \
--property=RestartForceExitStatus=133 \
--setenv=SYSTEMD_NSPAWN_LOCK=0 \
-- \
systemd-nspawn \
--keep-unit \
--quiet \
--boot \
--machine=k3s \
--directory=/opt/container/k3s \
--notify-ready=yes \
--capability=all \
--private-users=no \
--system-call-filter=bpf \
--system-call-filter=keyctl \
--system-call-filter=add_key \
--resolv-conf=bind-host \
--network-macvlan=ens33 \
--inaccessible=/sys/module/apparmor \
--bind-ro=/sys/module \
--bind=/dev/kmsg
# https://www.freedesktop.org/software/systemd/man/latest/systemd.network.html
cat << EOF > /etc/systemd/network/80-container-mv.network
[Match]
Virtualization=container
Name=mv-*
[Network]
DHCP=yes
LinkLocalAddressing=yes
[DHCP]
UseDNS=true
UseTimezone=yes
EOF
systemctl enable --now systemd-networkd
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment