summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2026-04-06 20:47:03 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2026-04-06 23:49:24 +0000
commit545ecc18af39a48a0543c844aa1652c2ed29c5d0 (patch)
tree8afe2bcdfe4acee86ebe0c15b274df91cd439f15
parentac89a0c46589c79c6ff583a11e0284e54af6a2cb (diff)
downloadmeta-virtualization-545ecc18af39a48a0543c844aa1652c2ed29c5d0.tar.gz
k3s: embed manifests and traefik charts, add server config
Embed system manifests and Helm charts into the k3s binary so that k3s's deploy.Stage() can extract and process them at runtime with template variable substitution (e.g., %{SYSTEM_DEFAULT_REGISTRY}%). Previously, raw manifest files were installed directly to the server manifests directory, but template variables were not substituted, causing InvalidImageName errors for system pods. Now manifests are copied to pkg/deploy/embed/ before Go compilation, matching upstream's scripts/build workflow. Traefik ingress controller support is added as a PACKAGECONFIG option (enabled by default). When enabled, the traefik and traefik-crd Helm chart tarballs are downloaded during do_fetch and embedded into the binary at pkg/static/embed/charts/. When disabled, traefik is added to the disable list in config.yaml. A default /etc/rancher/k3s/config.yaml is installed that disables the cloud-controller-manager (not needed for standalone/QEMU environments) and conditionally disables traefik. The --disable-cloud-controller flag is removed from k3s.service since it is now in the config file. To disable traefik: PACKAGECONFIG:remove:pn-k3s = "traefik" Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
-rw-r--r--recipes-containers/k3s/k3s/k3s.service2
-rw-r--r--recipes-containers/k3s/k3s_git.bb46
2 files changed, 44 insertions, 4 deletions
diff --git a/recipes-containers/k3s/k3s/k3s.service b/recipes-containers/k3s/k3s/k3s.service
index 42dc1832..f56110a4 100644
--- a/recipes-containers/k3s/k3s/k3s.service
+++ b/recipes-containers/k3s/k3s/k3s.service
@@ -34,7 +34,7 @@ ExecStartPre=-/sbin/modprobe overlay
34# Create flannel subnet.env if not present — k3s's embedded flannel 34# Create flannel subnet.env if not present — k3s's embedded flannel
35# controller expects this file for CNI plugin configuration 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' 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 37ExecStart=/usr/local/bin/k3s server
38# 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
39# 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
40# services and containers 40# services and containers
diff --git a/recipes-containers/k3s/k3s_git.bb b/recipes-containers/k3s/k3s_git.bb
index f478592f..e2d0a33e 100644
--- a/recipes-containers/k3s/k3s_git.bb
+++ b/recipes-containers/k3s/k3s_git.bb
@@ -13,6 +13,18 @@ SRC_URI = "git://github.com/rancher/k3s.git;branch=release-1.35;name=k3s;protoco
13 file://k3s-killall.sh \ 13 file://k3s-killall.sh \
14 " 14 "
15 15
16# Traefik Helm charts — downloaded and embedded into the k3s binary
17# so they can be served via the k3s static chart endpoint at runtime.
18# Opt-in via PACKAGECONFIG since traefik is not needed for basic k3s
19# operation and the chart images must be pullable at runtime.
20TRAEFIK_CHART_VERSION = "39.0.501+up39.0.5"
21SRC_URI += "${@bb.utils.contains('PACKAGECONFIG', 'traefik', \
22 'https://k3s.io/k3s-charts/assets/traefik-crd/traefik-crd-${TRAEFIK_CHART_VERSION}.tgz;name=traefik-crd;unpack=0;subdir=charts \
23 https://k3s.io/k3s-charts/assets/traefik/traefik-${TRAEFIK_CHART_VERSION}.tgz;name=traefik;unpack=0;subdir=charts', \
24 '', d)}"
25SRC_URI[traefik-crd.sha256sum] = "c6245bdcfd193d10ec956d90c50e0d1a3fa1bde541df80744e72eee91b054640"
26SRC_URI[traefik.sha256sum] = "888de9d098769b9199238076bee225d1b10dba1e889b0e28127eddc38cdb435b"
27
16SRC_URI[k3s.md5sum] = "363d3a08dc0b72ba6e6577964f6e94a5" 28SRC_URI[k3s.md5sum] = "363d3a08dc0b72ba6e6577964f6e94a5"
17SRCREV_k3s = "4841276da0cf9f6f3e323b6cc8b10da381331f98" 29SRCREV_k3s = "4841276da0cf9f6f3e323b6cc8b10da381331f98"
18 30
@@ -22,6 +34,9 @@ PV = "v1.35.2+k3s1+git"
22# K3s uses flannel for CNI networking, not the containerd bridge config 34# K3s uses flannel for CNI networking, not the containerd bridge config
23CNI_NETWORKING_FILES ?= "${UNPACKDIR}/cni-flannel.conflist" 35CNI_NETWORKING_FILES ?= "${UNPACKDIR}/cni-flannel.conflist"
24 36
37PACKAGECONFIG ??= "traefik"
38PACKAGECONFIG[traefik] = ",,,"
39
25# Build tags - used by both do_compile and do_discover_modules 40# Build tags - used by both do_compile and do_discover_modules
26TAGS = "static_build netcgo osusergo providerless" 41TAGS = "static_build netcgo osusergo providerless"
27 42
@@ -89,6 +104,20 @@ do_compile() {
89 # go.mod and go.sum are synchronized by do_sync_go_files task 104 # go.mod and go.sum are synchronized by do_sync_go_files task
90 # No manual fixes needed - discovery and recipe generation handle version matching 105 # No manual fixes needed - discovery and recipe generation handle version matching
91 106
107 # Populate embed directories before build — upstream scripts/build
108 # does this to embed manifests and static content into the binary
109 # via go:embed. Without this, k3s's deploy.Stage() has no manifests
110 # to process and system components (coredns, metrics-server, etc.)
111 # are not deployed on first server start.
112 cp -a manifests/* pkg/deploy/embed/
113
114 # Embed traefik Helm charts if enabled via PACKAGECONFIG
115 if ${@bb.utils.contains('PACKAGECONFIG', 'traefik', 'true', 'false', d)}; then
116 mkdir -p pkg/static/embed/charts
117 cp -a ${WORKDIR}/sources/charts/traefik-crd-${TRAEFIK_CHART_VERSION}.tgz pkg/static/embed/charts/
118 cp -a ${WORKDIR}/sources/charts/traefik-${TRAEFIK_CHART_VERSION}.tgz pkg/static/embed/charts/
119 fi
120
92 VERSION_GOLANG="$(go version | cut -d" " -f3)" 121 VERSION_GOLANG="$(go version | cut -d" " -f3)"
93 ${GO} build -trimpath -tags "${TAGS}" -ldflags "-X github.com/k3s-io/k3s/pkg/version.UpstreamGolang=$VERSION_GOLANG ${GO_BUILD_LDFLAGS} -w -s" -o ./dist/artifacts/k3s ./cmd/server/main.go 122 ${GO} build -trimpath -tags "${TAGS}" -ldflags "-X github.com/k3s-io/k3s/pkg/version.UpstreamGolang=$VERSION_GOLANG ${GO_BUILD_LDFLAGS} -w -s" -o ./dist/artifacts/k3s ./cmd/server/main.go
94 123
@@ -118,9 +147,20 @@ do_install() {
118 mkdir -p ${D}${datadir}/k3s/ 147 mkdir -p ${D}${datadir}/k3s/
119 install -m 0755 ${S}/src/import/contrib/util/check-config.sh ${D}${datadir}/k3s/ 148 install -m 0755 ${S}/src/import/contrib/util/check-config.sh ${D}${datadir}/k3s/
120 149
121 # Create server manifests directory — k3s expects this at startup for 150 # Create server manifests directory — k3s's deploy.Stage() writes
122 # auto-deploying system components (coredns, traefik, etc.) 151 # processed manifests here at runtime (template variables substituted)
123 install -d "${D}/var/lib/rancher/k3s/server/manifests" 152 install -d "${D}/var/lib/rancher/k3s/server/manifests"
153
154 # Install default k3s config — disable traefik if not in PACKAGECONFIG
155 install -d "${D}${sysconfdir}/rancher/k3s"
156 echo "# k3s server configuration (generated by recipe)" \
157 > "${D}${sysconfdir}/rancher/k3s/config.yaml"
158 echo "disable-cloud-controller: true" \
159 >> "${D}${sysconfdir}/rancher/k3s/config.yaml"
160 if ! ${@bb.utils.contains('PACKAGECONFIG', 'traefik', 'true', 'false', d)}; then
161 echo "disable:" >> "${D}${sysconfdir}/rancher/k3s/config.yaml"
162 echo " - traefik" >> "${D}${sysconfdir}/rancher/k3s/config.yaml"
163 fi
124} 164}
125 165
126PACKAGES =+ "${PN}-server ${PN}-agent" 166PACKAGES =+ "${PN}-server ${PN}-agent"
@@ -131,7 +171,7 @@ SYSTEMD_SERVICE:${PN}-agent = "${@bb.utils.contains('DISTRO_FEATURES','systemd',
131SYSTEMD_AUTO_ENABLE:${PN}-agent = "disable" 171SYSTEMD_AUTO_ENABLE:${PN}-agent = "disable"
132 172
133FILES:${PN}-agent = "${BIN_PREFIX}/bin/k3s-agent" 173FILES:${PN}-agent = "${BIN_PREFIX}/bin/k3s-agent"
134FILES:${PN} += "${BIN_PREFIX}/bin/*" 174FILES:${PN} += "${BIN_PREFIX}/bin/* /var/lib/rancher/k3s/server/manifests ${sysconfdir}/rancher/k3s"
135 175
136RDEPENDS:${PN} = "k3s-cni conntrack-tools coreutils findutils iptables iproute2 ipset virtual-containerd" 176RDEPENDS:${PN} = "k3s-cni conntrack-tools coreutils findutils iptables iproute2 ipset virtual-containerd"
137RDEPENDS:${PN}-server = "${PN}" 177RDEPENDS:${PN}-server = "${PN}"