diff options
| -rw-r--r-- | recipes-containers/k3s/README.md | 30 | ||||
| -rw-r--r-- | recipes-containers/k3s/k3s/0001-Finding-host-local-in-usr-libexec.patch | 27 | ||||
| -rw-r--r-- | recipes-containers/k3s/k3s/cni-containerd-net.conf | 24 | ||||
| -rwxr-xr-x | recipes-containers/k3s/k3s/k3s-agent | 103 | ||||
| -rw-r--r-- | recipes-containers/k3s/k3s/k3s-agent.service | 26 | ||||
| -rwxr-xr-x | recipes-containers/k3s/k3s/k3s-clean | 30 | ||||
| -rw-r--r-- | recipes-containers/k3s/k3s/k3s.service | 27 | ||||
| -rw-r--r-- | recipes-containers/k3s/k3s_git.bb | 75 |
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 | |||
| 3 | Rancher's [k3s](https://k3s.io/), available under | ||
| 4 | [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0), provides | ||
| 5 | lightweight Kubernetes suitable for small/edge devices. There are use cases | ||
| 6 | where the | ||
| 7 | [installation procedures provided by Rancher](https://rancher.com/docs/k3s/latest/en/installation/) | ||
| 8 | are not ideal but a bitbake-built version is what is needed. And only a few | ||
| 9 | mods to the [k3s source code](https://github.com/rancher/k3s) is needed to | ||
| 10 | accomplish that. | ||
| 11 | |||
| 12 | ## CNI | ||
| 13 | |||
| 14 | By default, K3s will run with flannel as the CNI, using VXLAN as the default | ||
| 15 | backend. It is both possible to change the flannel backend and to change from | ||
| 16 | flannel to another CNI. | ||
| 17 | |||
| 18 | Please see <https://rancher.com/docs/k3s/latest/en/installation/network-options/> | ||
| 19 | for further k3s networking details. | ||
| 20 | |||
| 21 | ## Configure and run a k3s agent | ||
| 22 | |||
| 23 | The convenience script `k3s-agent` can be used to set up a k3s agent (service): | ||
| 24 | |||
| 25 | ```shell | ||
| 26 | k3s-agent -t <token> -s https://<master>:6443 | ||
| 27 | ``` | ||
| 28 | |||
| 29 | (Here `<token>` is found in `/var/lib/rancher/k3s/server/node-token` at the | ||
| 30 | k3s 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 @@ | |||
| 1 | From 4faf68d68c97cfd10947e1152f711acc59f39647 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Erik Jansson <erikja@axis.com> | ||
| 3 | Date: Wed, 16 Oct 2019 15:07:48 +0200 | ||
| 4 | Subject: [PATCH] Finding host-local in /usr/libexec | ||
| 5 | |||
| 6 | Upstream-status: Inappropriate [embedded specific] | ||
| 7 | Signed-off-by: <erikja@axis.com> | ||
| 8 | --- | ||
| 9 | pkg/agent/config/config.go | 2 +- | ||
| 10 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
| 11 | |||
| 12 | diff --git a/pkg/agent/config/config.go b/pkg/agent/config/config.go | ||
| 13 | index 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 | -- | ||
| 26 | 2.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 | |||
| 7 | ENV_CONF=/etc/systemd/system/k3s-agent.service.d/10-env.conf | ||
| 8 | |||
| 9 | usage() { | ||
| 10 | echo " | ||
| 11 | USAGE: | ||
| 12 | ${0##*/} [OPTIONS] | ||
| 13 | OPTIONS: | ||
| 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 | |||
| 29 | case $1 in | ||
| 30 | -*) | ||
| 31 | ;; | ||
| 32 | *) | ||
| 33 | usage | ||
| 34 | exit 1 | ||
| 35 | ;; | ||
| 36 | esac | ||
| 37 | |||
| 38 | rm -f $ENV_CONF | ||
| 39 | mkdir -p ${ENV_CONF%/*} | ||
| 40 | echo [Service] > $ENV_CONF | ||
| 41 | |||
| 42 | while 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 | ||
| 97 | done | ||
| 98 | |||
| 99 | chmod 0644 $ENV_CONF | ||
| 100 | rm -rf /var/lib/rancher/k3s/agent | ||
| 101 | systemctl daemon-reload | ||
| 102 | systemctl restart k3s-agent | ||
| 103 | systemctl 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] | ||
| 3 | Description=Lightweight Kubernetes Agent | ||
| 4 | Documentation=https://k3s.io | ||
| 5 | Requires=containerd.service | ||
| 6 | After=containerd.service | ||
| 7 | |||
| 8 | [Install] | ||
| 9 | WantedBy=multi-user.target | ||
| 10 | |||
| 11 | [Service] | ||
| 12 | Type=notify | ||
| 13 | KillMode=control-group | ||
| 14 | Delegate=yes | ||
| 15 | LimitNOFILE=infinity | ||
| 16 | LimitNPROC=infinity | ||
| 17 | LimitCORE=infinity | ||
| 18 | TasksMax=infinity | ||
| 19 | TimeoutStartSec=0 | ||
| 20 | Restart=always | ||
| 21 | RestartSec=5s | ||
| 22 | ExecStartPre=-/sbin/modprobe br_netfilter | ||
| 23 | ExecStartPre=-/sbin/modprobe overlay | ||
| 24 | ExecStart=/usr/local/bin/k3s agent | ||
| 25 | ExecStopPost=/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 | |||
| 7 | do_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 | |||
| 20 | do_unmount /run/k3s /var/lib/rancher/k3s | ||
| 21 | |||
| 22 | # The lines below come from install.sh's create_killall() function: | ||
| 23 | ip link show 2>/dev/null | grep 'master cni0' | while read ignore iface ignore; do | ||
| 24 | iface=${iface%%@*} | ||
| 25 | [ -z "$iface" ] || ip link delete $iface | ||
| 26 | done | ||
| 27 | |||
| 28 | ip link delete cni0 | ||
| 29 | ip link delete flannel.1 | ||
| 30 | rm -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] | ||
| 3 | Description=Lightweight Kubernetes | ||
| 4 | Documentation=https://k3s.io | ||
| 5 | Requires=containerd.service | ||
| 6 | After=containerd.service | ||
| 7 | |||
| 8 | [Install] | ||
| 9 | WantedBy=multi-user.target | ||
| 10 | |||
| 11 | [Service] | ||
| 12 | Type=notify | ||
| 13 | KillMode=process | ||
| 14 | Delegate=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. | ||
| 17 | LimitNOFILE=1048576 | ||
| 18 | LimitNPROC=infinity | ||
| 19 | LimitCORE=infinity | ||
| 20 | TasksMax=infinity | ||
| 21 | TimeoutStartSec=0 | ||
| 22 | Restart=always | ||
| 23 | RestartSec=5s | ||
| 24 | ExecStartPre=-/sbin/modprobe br_netfilter | ||
| 25 | ExecStartPre=-/sbin/modprobe overlay | ||
| 26 | ExecStart=/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 @@ | |||
| 1 | SUMMARY = "Production-Grade Container Scheduling and Management" | ||
| 2 | DESCRIPTION = "Lightweight Kubernetes, intended to be a fully compliant Kubernetes." | ||
| 3 | HOMEPAGE = "https://k3s.io/" | ||
| 4 | LICENSE = "Apache-2.0" | ||
| 5 | LIC_FILES_CHKSUM = "file://${S}/src/import/LICENSE;md5=2ee41112a44fe7014dce33e26468ba93" | ||
| 6 | PV = "v1.18.9+k3s1-dirty" | ||
| 7 | |||
| 8 | SRC_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 | " | ||
| 16 | SRC_URI[k3s.md5sum] = "363d3a08dc0b72ba6e6577964f6e94a5" | ||
| 17 | SRCREV_k3s = "630bebf94b9dce6b8cd3d402644ed023b3af8f90" | ||
| 18 | |||
| 19 | inherit go | ||
| 20 | inherit goarch | ||
| 21 | inherit systemd | ||
| 22 | |||
| 23 | PACKAGECONFIG = "" | ||
| 24 | PACKAGECONFIG[upx] = ",,upx-native" | ||
| 25 | GO_IMPORT = "import" | ||
| 26 | GO_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 | " | ||
| 30 | BIN_PREFIX ?= "${exec_prefix}/local" | ||
| 31 | |||
| 32 | do_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 | } | ||
| 43 | do_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 | |||
| 59 | PACKAGES =+ "${PN}-server ${PN}-agent" | ||
| 60 | |||
| 61 | SYSTEMD_PACKAGES = "${@bb.utils.contains('DISTRO_FEATURES','systemd','${PN}-server ${PN}-agent','',d)}" | ||
| 62 | SYSTEMD_SERVICE_${PN}-server = "${@bb.utils.contains('DISTRO_FEATURES','systemd','k3s.service','',d)}" | ||
| 63 | SYSTEMD_SERVICE_${PN}-agent = "${@bb.utils.contains('DISTRO_FEATURES','systemd','k3s-agent.service','',d)}" | ||
| 64 | SYSTEMD_AUTO_ENABLE_${PN}-agent = "disable" | ||
| 65 | |||
| 66 | FILES_${PN}-agent = "${BIN_PREFIX}/bin/k3s-agent" | ||
| 67 | |||
| 68 | RDEPENDS_${PN} = "cni conntrack-tools coreutils findutils iproute2 ipset virtual/containerd" | ||
| 69 | RDEPENDS_${PN}-server = "${PN}" | ||
| 70 | RDEPENDS_${PN}-agent = "${PN}" | ||
| 71 | |||
| 72 | RCONFLICTS_${PN} = "kubectl" | ||
| 73 | |||
| 74 | INHIBIT_PACKAGE_STRIP = "1" | ||
| 75 | INSANE_SKIP_${PN} += "ldflags already-stripped" | ||
