summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2026-04-06 15:49:46 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2026-04-06 23:49:24 +0000
commit540f1aee43c9694912869ef6d32a570ffbf7c123 (patch)
treed3b43fe8ba72bd22ea33984c02c9f659f35d10a5
parenta4cd368b40d5f95d759548e45475d62555b08cf5 (diff)
downloadmeta-virtualization-540f1aee43c9694912869ef6d32a570ffbf7c123.tar.gz
k3s: fix CNI networking, service PATH, and manifests directory
Several issues prevented k3s from starting and running pods in the Yocto image: k3s.service / k3s-agent.service: - Add /opt/cni/bin and /usr/libexec/cni to PATH so k3s can find CNI plugin binaries (host-local, flannel, bridge, etc.) - Create /run/flannel/subnet.env at startup if not present — k3s's embedded flannel controller expects this file for CNI configuration - Add --disable-cloud-controller to server — the cloud controller manager is for cloud provider integration (AWS/GCP) and causes a timeout loop in standalone/QEMU environments k3s_git.bb: - Create /var/lib/rancher/k3s/server/manifests/ directory — k3s expects this at startup for auto-deploying system components - Switch CNI config from cni-containerd-net.conf (containerd bridge with 10.88.0.0/16 subnet) to cni-flannel.conflist which matches k3s's flannel networking (10.42.0.0/16 via flannel plugin) cni-flannel.conflist: - New flannel CNI config that delegates to the flannel plugin with hairpin mode, forceAddress, and portmap capabilities Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
-rw-r--r--recipes-containers/k3s/k3s/cni-flannel.conflist20
-rw-r--r--recipes-containers/k3s/k3s/k3s-agent.service6
-rw-r--r--recipes-containers/k3s/k3s/k3s.service7
-rw-r--r--recipes-containers/k3s/k3s_git.bb9
4 files changed, 39 insertions, 3 deletions
diff --git a/recipes-containers/k3s/k3s/cni-flannel.conflist b/recipes-containers/k3s/k3s/cni-flannel.conflist
new file mode 100644
index 00000000..afa9afb0
--- /dev/null
+++ b/recipes-containers/k3s/k3s/cni-flannel.conflist
@@ -0,0 +1,20 @@
1{
2 "name": "cbr0",
3 "cniVersion": "1.0.0",
4 "plugins": [
5 {
6 "type": "flannel",
7 "delegate": {
8 "hairpinMode": true,
9 "forceAddress": true,
10 "isDefaultGateway": true
11 }
12 },
13 {
14 "type": "portmap",
15 "capabilities": {
16 "portMappings": true
17 }
18 }
19 ]
20}
diff --git a/recipes-containers/k3s/k3s/k3s-agent.service b/recipes-containers/k3s/k3s/k3s-agent.service
index 9f9016da..40d0564b 100644
--- a/recipes-containers/k3s/k3s/k3s-agent.service
+++ b/recipes-containers/k3s/k3s/k3s-agent.service
@@ -10,6 +10,8 @@ WantedBy=multi-user.target
10 10
11[Service] 11[Service]
12Type=notify 12Type=notify
13# Ensure CNI plugin binaries are discoverable
14Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/cni/bin:/usr/libexec/cni
13KillMode=control-group 15KillMode=control-group
14Delegate=yes 16Delegate=yes
15LimitNOFILE=infinity 17LimitNOFILE=infinity
@@ -21,6 +23,10 @@ Restart=always
21RestartSec=5s 23RestartSec=5s
22ExecStartPre=-/sbin/modprobe br_netfilter 24ExecStartPre=-/sbin/modprobe br_netfilter
23ExecStartPre=-/sbin/modprobe overlay 25ExecStartPre=-/sbin/modprobe overlay
26# Create flannel subnet.env if not present — k3s's embedded flannel
27# controller populates this after joining, but the CNI plugin needs
28# the file to exist at sandbox creation time
29ExecStartPre=/bin/sh -c 'mkdir -p /run/flannel && test -f /run/flannel/subnet.env || echo "FLANNEL_NETWORK=10.42.0.0/16\nFLANNEL_SUBNET=10.42.0.1/24\nFLANNEL_MTU=1450\nFLANNEL_IPMASQ=true" > /run/flannel/subnet.env'
24ExecStart=/usr/local/bin/k3s agent 30ExecStart=/usr/local/bin/k3s agent
25ExecStopPost=/usr/local/bin/k3s-clean 31ExecStopPost=/usr/local/bin/k3s-clean
26 32
diff --git a/recipes-containers/k3s/k3s/k3s.service b/recipes-containers/k3s/k3s/k3s.service
index 33d3ee74..42dc1832 100644
--- a/recipes-containers/k3s/k3s/k3s.service
+++ b/recipes-containers/k3s/k3s/k3s.service
@@ -15,6 +15,8 @@ Type=notify
15EnvironmentFile=-/etc/default/%N 15EnvironmentFile=-/etc/default/%N
16EnvironmentFile=-/etc/sysconfig/%N 16EnvironmentFile=-/etc/sysconfig/%N
17EnvironmentFile=-/etc/systemd/system/k3s.service.env 17EnvironmentFile=-/etc/systemd/system/k3s.service.env
18# Ensure CNI plugin binaries are discoverable
19Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/cni/bin:/usr/libexec/cni
18KillMode=process 20KillMode=process
19Delegate=yes 21Delegate=yes
20# Having non-zero Limit*s causes performance problems due to accounting overhead 22# Having non-zero Limit*s causes performance problems due to accounting overhead
@@ -29,7 +31,10 @@ RestartSec=5s
29ExecStartPre=/bin/sh -xc '! systemctl is-enabled --quiet nm-cloud-setup.service' 31ExecStartPre=/bin/sh -xc '! systemctl is-enabled --quiet nm-cloud-setup.service'
30ExecStartPre=-/sbin/modprobe br_netfilter 32ExecStartPre=-/sbin/modprobe br_netfilter
31ExecStartPre=-/sbin/modprobe overlay 33ExecStartPre=-/sbin/modprobe overlay
32ExecStart=/usr/local/bin/k3s server 34# Create flannel subnet.env if not present — k3s's embedded flannel
35# controller expects this file for CNI plugin configuration
36ExecStartPre=/bin/sh -c 'mkdir -p /run/flannel && test -f /run/flannel/subnet.env || echo "FLANNEL_NETWORK=10.42.0.0/16\nFLANNEL_SUBNET=10.42.0.1/24\nFLANNEL_MTU=1450\nFLANNEL_IPMASQ=true" > /run/flannel/subnet.env'
37ExecStart=/usr/local/bin/k3s server --disable-cloud-controller
33# Avoid any delay due to this service when the system is rebooting or shutting 38# Avoid any delay due to this service when the system is rebooting or shutting
34# down by using the k3s-killall.sh script to kill all of the running k3s 39# down by using the k3s-killall.sh script to kill all of the running k3s
35# services and containers 40# services and containers
diff --git a/recipes-containers/k3s/k3s_git.bb b/recipes-containers/k3s/k3s_git.bb
index 4a747752..f478592f 100644
--- a/recipes-containers/k3s/k3s_git.bb
+++ b/recipes-containers/k3s/k3s_git.bb
@@ -9,7 +9,7 @@ SRC_URI = "git://github.com/rancher/k3s.git;branch=release-1.35;name=k3s;protoco
9 file://k3s-agent.service \ 9 file://k3s-agent.service \
10 file://k3s-agent \ 10 file://k3s-agent \
11 file://k3s-clean \ 11 file://k3s-clean \
12 file://cni-containerd-net.conf \ 12 file://cni-flannel.conflist \
13 file://k3s-killall.sh \ 13 file://k3s-killall.sh \
14 " 14 "
15 15
@@ -19,7 +19,8 @@ SRCREV_k3s = "4841276da0cf9f6f3e323b6cc8b10da381331f98"
19SRCREV_FORMAT = "k3s_fuse" 19SRCREV_FORMAT = "k3s_fuse"
20PV = "v1.35.2+k3s1+git" 20PV = "v1.35.2+k3s1+git"
21 21
22CNI_NETWORKING_FILES ?= "${UNPACKDIR}/cni-containerd-net.conf" 22# K3s uses flannel for CNI networking, not the containerd bridge config
23CNI_NETWORKING_FILES ?= "${UNPACKDIR}/cni-flannel.conflist"
23 24
24# Build tags - used by both do_compile and do_discover_modules 25# Build tags - used by both do_compile and do_discover_modules
25TAGS = "static_build netcgo osusergo providerless" 26TAGS = "static_build netcgo osusergo providerless"
@@ -116,6 +117,10 @@ do_install() {
116 117
117 mkdir -p ${D}${datadir}/k3s/ 118 mkdir -p ${D}${datadir}/k3s/
118 install -m 0755 ${S}/src/import/contrib/util/check-config.sh ${D}${datadir}/k3s/ 119 install -m 0755 ${S}/src/import/contrib/util/check-config.sh ${D}${datadir}/k3s/
120
121 # Create server manifests directory — k3s expects this at startup for
122 # auto-deploying system components (coredns, traefik, etc.)
123 install -d "${D}/var/lib/rancher/k3s/server/manifests"
119} 124}
120 125
121PACKAGES =+ "${PN}-server ${PN}-agent" 126PACKAGES =+ "${PN}-server ${PN}-agent"