summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--recipes-containers/k3s/README.md30
-rw-r--r--recipes-containers/k3s/k3s/0001-Finding-host-local-in-usr-libexec.patch27
-rw-r--r--recipes-containers/k3s/k3s/cni-containerd-net.conf24
-rwxr-xr-xrecipes-containers/k3s/k3s/k3s-agent103
-rw-r--r--recipes-containers/k3s/k3s/k3s-agent.service26
-rwxr-xr-xrecipes-containers/k3s/k3s/k3s-clean30
-rw-r--r--recipes-containers/k3s/k3s/k3s.service27
-rw-r--r--recipes-containers/k3s/k3s_git.bb75
8 files changed, 342 insertions, 0 deletions
diff --git a/recipes-containers/k3s/README.md b/recipes-containers/k3s/README.md
new file mode 100644
index 00000000..3fe5ccd1
--- /dev/null
+++ b/recipes-containers/k3s/README.md
@@ -0,0 +1,30 @@
1# k3s: Lightweight Kubernetes
2
3Rancher's [k3s](https://k3s.io/), available under
4[Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0), provides
5lightweight Kubernetes suitable for small/edge devices. There are use cases
6where the
7[installation procedures provided by Rancher](https://rancher.com/docs/k3s/latest/en/installation/)
8are not ideal but a bitbake-built version is what is needed. And only a few
9mods to the [k3s source code](https://github.com/rancher/k3s) is needed to
10accomplish that.
11
12## CNI
13
14By default, K3s will run with flannel as the CNI, using VXLAN as the default
15backend. It is both possible to change the flannel backend and to change from
16flannel to another CNI.
17
18Please see <https://rancher.com/docs/k3s/latest/en/installation/network-options/>
19for further k3s networking details.
20
21## Configure and run a k3s agent
22
23The convenience script `k3s-agent` can be used to set up a k3s agent (service):
24
25```shell
26k3s-agent -t <token> -s https://<master>:6443
27```
28
29(Here `<token>` is found in `/var/lib/rancher/k3s/server/node-token` at the
30k3s master.)
diff --git a/recipes-containers/k3s/k3s/0001-Finding-host-local-in-usr-libexec.patch b/recipes-containers/k3s/k3s/0001-Finding-host-local-in-usr-libexec.patch
new file mode 100644
index 00000000..8205d735
--- /dev/null
+++ b/recipes-containers/k3s/k3s/0001-Finding-host-local-in-usr-libexec.patch
@@ -0,0 +1,27 @@
1From 4faf68d68c97cfd10947e1152f711acc59f39647 Mon Sep 17 00:00:00 2001
2From: Erik Jansson <erikja@axis.com>
3Date: Wed, 16 Oct 2019 15:07:48 +0200
4Subject: [PATCH] Finding host-local in /usr/libexec
5
6Upstream-status: Inappropriate [embedded specific]
7Signed-off-by: <erikja@axis.com>
8---
9 pkg/agent/config/config.go | 2 +-
10 1 file changed, 1 insertion(+), 1 deletion(-)
11
12diff --git a/pkg/agent/config/config.go b/pkg/agent/config/config.go
13index b4296f360a..6af9dab895 100644
14--- a/pkg/agent/config/config.go
15+++ b/pkg/agent/config/config.go
16@@ -308,7 +308,7 @@ func get(envInfo *cmds.Agent) (*config.Node, error) {
17 return nil, err
18 }
19
20- hostLocal, err := exec.LookPath("host-local")
21+ hostLocal, err := exec.LookPath("/usr/libexec/cni/host-local")
22 if err != nil {
23 return nil, errors.Wrapf(err, "failed to find host-local")
24 }
25--
262.11.0
27
diff --git a/recipes-containers/k3s/k3s/cni-containerd-net.conf b/recipes-containers/k3s/k3s/cni-containerd-net.conf
new file mode 100644
index 00000000..ca434d6f
--- /dev/null
+++ b/recipes-containers/k3s/k3s/cni-containerd-net.conf
@@ -0,0 +1,24 @@
1{
2 "cniVersion": "0.4.0",
3 "name": "containerd-net",
4 "plugins": [
5 {
6 "type": "bridge",
7 "bridge": "cni0",
8 "isGateway": true,
9 "ipMasq": true,
10 "promiscMode": true,
11 "ipam": {
12 "type": "host-local",
13 "subnet": "10.88.0.0/16",
14 "routes": [
15 { "dst": "0.0.0.0/0" }
16 ]
17 }
18 },
19 {
20 "type": "portmap",
21 "capabilities": {"portMappings": true}
22 }
23 ]
24}
diff --git a/recipes-containers/k3s/k3s/k3s-agent b/recipes-containers/k3s/k3s/k3s-agent
new file mode 100755
index 00000000..b6c6cb62
--- /dev/null
+++ b/recipes-containers/k3s/k3s/k3s-agent
@@ -0,0 +1,103 @@
1#!/bin/sh -eu
2#
3# Copyright (C) 2020 Axis Communications AB
4#
5# SPDX-License-Identifier: Apache-2.0
6
7ENV_CONF=/etc/systemd/system/k3s-agent.service.d/10-env.conf
8
9usage() {
10 echo "
11USAGE:
12 ${0##*/} [OPTIONS]
13OPTIONS:
14 --token value, -t value Token to use for authentication [\$K3S_TOKEN]
15 --token-file value Token file to use for authentication [\$K3S_TOKEN_FILE]
16 --server value, -s value Server to connect to [\$K3S_URL]
17 --node-name value Node name [\$K3S_NODE_NAME]
18 --resolv-conf value Kubelet resolv.conf file [\$K3S_RESOLV_CONF]
19 --cluster-secret value Shared secret used to bootstrap a cluster [\$K3S_CLUSTER_SECRET]
20 -h print this
21"
22}
23
24[ $# -gt 0 ] || {
25 usage
26 exit
27}
28
29case $1 in
30 -*)
31 ;;
32 *)
33 usage
34 exit 1
35 ;;
36esac
37
38rm -f $ENV_CONF
39mkdir -p ${ENV_CONF%/*}
40echo [Service] > $ENV_CONF
41
42while getopts "t:s:-:h" opt; do
43 case $opt in
44 h)
45 usage
46 exit
47 ;;
48 t)
49 VAR_NAME=K3S_TOKEN
50 ;;
51 s)
52 VAR_NAME=K3S_URL
53 ;;
54 -)
55 [ $# -ge $OPTIND ] || {
56 usage
57 exit 1
58 }
59 opt=$OPTARG
60 eval OPTARG='$'$OPTIND
61 OPTIND=$(($OPTIND + 1))
62 case $opt in
63 token)
64 VAR_NAME=K3S_TOKEN
65 ;;
66 token-file)
67 VAR_NAME=K3S_TOKEN_FILE
68 ;;
69 server)
70 VAR_NAME=K3S_URL
71 ;;
72 node-name)
73 VAR_NAME=K3S_NODE_NAME
74 ;;
75 resolv-conf)
76 VAR_NAME=K3S_RESOLV_CONF
77 ;;
78 cluster-secret)
79 VAR_NAME=K3S_CLUSTER_SECRET
80 ;;
81 help)
82 usage
83 exit
84 ;;
85 *)
86 usage
87 exit 1
88 ;;
89 esac
90 ;;
91 *)
92 usage
93 exit 1
94 ;;
95 esac
96 echo Environment=$VAR_NAME=$OPTARG >> $ENV_CONF
97done
98
99chmod 0644 $ENV_CONF
100rm -rf /var/lib/rancher/k3s/agent
101systemctl daemon-reload
102systemctl restart k3s-agent
103systemctl enable k3s-agent.service
diff --git a/recipes-containers/k3s/k3s/k3s-agent.service b/recipes-containers/k3s/k3s/k3s-agent.service
new file mode 100644
index 00000000..9f9016da
--- /dev/null
+++ b/recipes-containers/k3s/k3s/k3s-agent.service
@@ -0,0 +1,26 @@
1# Derived from the k3s install.sh's create_systemd_service_file() function
2[Unit]
3Description=Lightweight Kubernetes Agent
4Documentation=https://k3s.io
5Requires=containerd.service
6After=containerd.service
7
8[Install]
9WantedBy=multi-user.target
10
11[Service]
12Type=notify
13KillMode=control-group
14Delegate=yes
15LimitNOFILE=infinity
16LimitNPROC=infinity
17LimitCORE=infinity
18TasksMax=infinity
19TimeoutStartSec=0
20Restart=always
21RestartSec=5s
22ExecStartPre=-/sbin/modprobe br_netfilter
23ExecStartPre=-/sbin/modprobe overlay
24ExecStart=/usr/local/bin/k3s agent
25ExecStopPost=/usr/local/bin/k3s-clean
26
diff --git a/recipes-containers/k3s/k3s/k3s-clean b/recipes-containers/k3s/k3s/k3s-clean
new file mode 100755
index 00000000..8eca918c
--- /dev/null
+++ b/recipes-containers/k3s/k3s/k3s-clean
@@ -0,0 +1,30 @@
1#!/bin/sh -eu
2#
3# Copyright (C) 2020 Axis Communications AB
4#
5# SPDX-License-Identifier: Apache-2.0
6
7do_unmount() {
8 [ $# -eq 2 ] || return
9 local mounts=
10 while read ignore mount ignore; do
11 case $mount in
12 $1/*|$2/*)
13 mounts="$mount $mounts"
14 ;;
15 esac
16 done </proc/self/mounts
17 [ -z "$mounts" ] || umount $mounts
18}
19
20do_unmount /run/k3s /var/lib/rancher/k3s
21
22# The lines below come from install.sh's create_killall() function:
23ip link show 2>/dev/null | grep 'master cni0' | while read ignore iface ignore; do
24 iface=${iface%%@*}
25 [ -z "$iface" ] || ip link delete $iface
26done
27
28ip link delete cni0
29ip link delete flannel.1
30rm -rf /var/lib/cni/
diff --git a/recipes-containers/k3s/k3s/k3s.service b/recipes-containers/k3s/k3s/k3s.service
new file mode 100644
index 00000000..34c7a804
--- /dev/null
+++ b/recipes-containers/k3s/k3s/k3s.service
@@ -0,0 +1,27 @@
1# Derived from the k3s install.sh's create_systemd_service_file() function
2[Unit]
3Description=Lightweight Kubernetes
4Documentation=https://k3s.io
5Requires=containerd.service
6After=containerd.service
7
8[Install]
9WantedBy=multi-user.target
10
11[Service]
12Type=notify
13KillMode=process
14Delegate=yes
15# Having non-zero Limit*s causes performance problems due to accounting overhead
16# in the kernel. We recommend using cgroups to do container-local accounting.
17LimitNOFILE=1048576
18LimitNPROC=infinity
19LimitCORE=infinity
20TasksMax=infinity
21TimeoutStartSec=0
22Restart=always
23RestartSec=5s
24ExecStartPre=-/sbin/modprobe br_netfilter
25ExecStartPre=-/sbin/modprobe overlay
26ExecStart=/usr/local/bin/k3s server
27
diff --git a/recipes-containers/k3s/k3s_git.bb b/recipes-containers/k3s/k3s_git.bb
new file mode 100644
index 00000000..cfc2c64c
--- /dev/null
+++ b/recipes-containers/k3s/k3s_git.bb
@@ -0,0 +1,75 @@
1SUMMARY = "Production-Grade Container Scheduling and Management"
2DESCRIPTION = "Lightweight Kubernetes, intended to be a fully compliant Kubernetes."
3HOMEPAGE = "https://k3s.io/"
4LICENSE = "Apache-2.0"
5LIC_FILES_CHKSUM = "file://${S}/src/import/LICENSE;md5=2ee41112a44fe7014dce33e26468ba93"
6PV = "v1.18.9+k3s1-dirty"
7
8SRC_URI = "git://github.com/rancher/k3s.git;branch=release-1.18;name=k3s \
9 file://k3s.service \
10 file://k3s-agent.service \
11 file://k3s-agent \
12 file://k3s-clean \
13 file://cni-containerd-net.conf \
14 file://0001-Finding-host-local-in-usr-libexec.patch;patchdir=src/import \
15 "
16SRC_URI[k3s.md5sum] = "363d3a08dc0b72ba6e6577964f6e94a5"
17SRCREV_k3s = "630bebf94b9dce6b8cd3d402644ed023b3af8f90"
18
19inherit go
20inherit goarch
21inherit systemd
22
23PACKAGECONFIG = ""
24PACKAGECONFIG[upx] = ",,upx-native"
25GO_IMPORT = "import"
26GO_BUILD_LDFLAGS = "-X github.com/rancher/k3s/pkg/version.Version=${PV} \
27 -X github.com/rancher/k3s/pkg/version.GitCommit=${@d.getVar('SRCREV_k3s', d, 1)[:8]} \
28 -w -s \
29 "
30BIN_PREFIX ?= "${exec_prefix}/local"
31
32do_compile() {
33 export GOPATH="${S}/src/import/.gopath:${S}/src/import/vendor:${STAGING_DIR_TARGET}/${prefix}/local/go"
34 export CGO_ENABLED="1"
35 export GOFLAGS="-mod=vendor"
36 cd ${S}/src/import
37 ${GO} build -tags providerless -ldflags "${GO_BUILD_LDFLAGS}" -o ./dist/artifacts/k3s ./cmd/server/main.go
38 # Use UPX if it is enabled (and thus exists) to compress binary
39 if command -v upx > /dev/null 2>&1; then
40 upx -9 ./dist/artifacts/k3s
41 fi
42}
43do_install() {
44 install -d "${D}${BIN_PREFIX}/bin"
45 install -m 755 "${S}/src/import/dist/artifacts/k3s" "${D}${BIN_PREFIX}/bin"
46 ln -sr "${D}/${BIN_PREFIX}/bin/k3s" "${D}${BIN_PREFIX}/bin/crictl"
47 ln -sr "${D}/${BIN_PREFIX}/bin/k3s" "${D}${BIN_PREFIX}/bin/ctr"
48 ln -sr "${D}/${BIN_PREFIX}/bin/k3s" "${D}${BIN_PREFIX}/bin/kubectl"
49 install -m 755 "${WORKDIR}/k3s-clean" "${D}${BIN_PREFIX}/bin"
50 install -D -m 0644 "${WORKDIR}/cni-containerd-net.conf" "${D}/${sysconfdir}/cni/net.d/10-containerd-net.conf"
51 if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
52 install -D -m 0644 "${WORKDIR}/k3s.service" "${D}${systemd_system_unitdir}/k3s.service"
53 install -D -m 0644 "${WORKDIR}/k3s-agent.service" "${D}${systemd_system_unitdir}/k3s-agent.service"
54 sed -i "s#\(Exec\)\(.*\)=\(.*\)\(k3s\)#\1\2=${BIN_PREFIX}/bin/\4#g" "${D}${systemd_system_unitdir}/k3s.service" "${D}${systemd_system_unitdir}/k3s-agent.service"
55 install -m 755 "${WORKDIR}/k3s-agent" "${D}${BIN_PREFIX}/bin"
56 fi
57}
58
59PACKAGES =+ "${PN}-server ${PN}-agent"
60
61SYSTEMD_PACKAGES = "${@bb.utils.contains('DISTRO_FEATURES','systemd','${PN}-server ${PN}-agent','',d)}"
62SYSTEMD_SERVICE_${PN}-server = "${@bb.utils.contains('DISTRO_FEATURES','systemd','k3s.service','',d)}"
63SYSTEMD_SERVICE_${PN}-agent = "${@bb.utils.contains('DISTRO_FEATURES','systemd','k3s-agent.service','',d)}"
64SYSTEMD_AUTO_ENABLE_${PN}-agent = "disable"
65
66FILES_${PN}-agent = "${BIN_PREFIX}/bin/k3s-agent"
67
68RDEPENDS_${PN} = "cni conntrack-tools coreutils findutils iproute2 ipset virtual/containerd"
69RDEPENDS_${PN}-server = "${PN}"
70RDEPENDS_${PN}-agent = "${PN}"
71
72RCONFLICTS_${PN} = "kubectl"
73
74INHIBIT_PACKAGE_STRIP = "1"
75INSANE_SKIP_${PN} += "ldflags already-stripped"