summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--recipes-containers/k3s/k3s/k3s-killall.sh82
-rw-r--r--recipes-containers/k3s/k3s/k3s.service12
-rw-r--r--recipes-containers/k3s/k3s_git.bb2
3 files changed, 95 insertions, 1 deletions
diff --git a/recipes-containers/k3s/k3s/k3s-killall.sh b/recipes-containers/k3s/k3s/k3s-killall.sh
new file mode 100644
index 00000000..9e726153
--- /dev/null
+++ b/recipes-containers/k3s/k3s/k3s-killall.sh
@@ -0,0 +1,82 @@
1#!/bin/sh
2
3# Based on: k3s-killall.sh installed when running Rancher Lab's K3S install.sh
4# In open-source project: https://github.com/k3s-io/k3s
5#
6# Original file: Copyright (c) 2021 Rancher Labs and Contributors.
7# Modifications: Copyright (c) 2021 Arm Limited and Contributors. All rights reserved.
8#
9# Modifications:
10# - Change systemd service directory location
11# - Fix PID parsing to run on core image
12# - Remove service stopping code (as this is intended to run as part of service
13# stop)
14# - Changes to resolve warnings from the ShellCheck static analysis tool
15#
16# SPDX-License-Identifier: Apache License 2.0
17
18[ "$(id -u)" -eq 0 ] || exec sudo "$0" "$@"
19
20for bin in /var/lib/rancher/k3s/data/**/bin/; do
21 [ -d "$bin" ] && export PATH=$PATH:$bin:$bin/aux
22done
23
24set -x
25
26pschildren() {
27 ps -e -o ppid= -o pid= | sed -e 's/^\s*//g; s/\s\s*/\t/g;' | grep -w "^$1" | cut -f2
28}
29
30pstree() {
31 for pid in "$@"; do
32 echo "$pid"
33 for child in $(pschildren "$pid"); do
34 pstree "$child"
35 done
36 done
37}
38
39killtree() {
40 while read -r pid; do
41 if [ -n "${pid}" ]; then
42 kill -9 "${pid}" 2>/dev/null
43 fi
44 done <<EOF
45$({ set +x; } 2>/dev/null; pstree "$@"; set -x;)
46EOF
47}
48
49getshims() {
50 ps -e -o pid= -o args= | sed -e 's/^ *//; s/\s\s*/\t/;' | grep -w '[^/]*/bin/containerd-shim' | cut -f1
51}
52
53killtree "$({ set +x; } 2>/dev/null; getshims; set -x)"
54
55# shellcheck disable=SC2016
56do_unmount_and_remove() {
57 set +x
58 while read -r _ path _; do
59 case "$path" in $1*) echo "$path" ;; esac
60 done < /proc/self/mounts | sort -r | xargs -r -t -n 1 sh -c 'umount "$0" && rm -rf "$0"'
61 set -x
62}
63
64do_unmount_and_remove '/run/k3s'
65do_unmount_and_remove '/var/lib/rancher/k3s'
66do_unmount_and_remove '/var/lib/kubelet/pods'
67do_unmount_and_remove '/var/lib/kubelet/plugins'
68do_unmount_and_remove '/run/netns/cni-'
69
70# Remove CNI namespaces
71ip netns show 2>/dev/null | grep cni- | xargs -r -t -n 1 ip netns delete
72
73# Delete network interface(s) that match 'master cni0'
74ip link show 2>/dev/null | grep 'master cni0' | while read -r _ iface _; do
75 iface=${iface%%@*}
76 [ -z "$iface" ] || ip link delete "$iface"
77done
78ip link delete cni0
79ip link delete flannel.1
80ip link delete flannel-v6.1
81rm -rf /var/lib/cni/
82iptables-save | grep -v KUBE- | grep -v CNI- | iptables-restore
diff --git a/recipes-containers/k3s/k3s/k3s.service b/recipes-containers/k3s/k3s/k3s.service
index 34c7a804..33d3ee74 100644
--- a/recipes-containers/k3s/k3s/k3s.service
+++ b/recipes-containers/k3s/k3s/k3s.service
@@ -4,12 +4,17 @@ Description=Lightweight Kubernetes
4Documentation=https://k3s.io 4Documentation=https://k3s.io
5Requires=containerd.service 5Requires=containerd.service
6After=containerd.service 6After=containerd.service
7After=network-online.target
8Wants=network-online.target
7 9
8[Install] 10[Install]
9WantedBy=multi-user.target 11WantedBy=multi-user.target
10 12
11[Service] 13[Service]
12Type=notify 14Type=notify
15EnvironmentFile=-/etc/default/%N
16EnvironmentFile=-/etc/sysconfig/%N
17EnvironmentFile=-/etc/systemd/system/k3s.service.env
13KillMode=process 18KillMode=process
14Delegate=yes 19Delegate=yes
15# Having non-zero Limit*s causes performance problems due to accounting overhead 20# Having non-zero Limit*s causes performance problems due to accounting overhead
@@ -21,7 +26,12 @@ TasksMax=infinity
21TimeoutStartSec=0 26TimeoutStartSec=0
22Restart=always 27Restart=always
23RestartSec=5s 28RestartSec=5s
29ExecStartPre=/bin/sh -xc '! systemctl is-enabled --quiet nm-cloud-setup.service'
24ExecStartPre=-/sbin/modprobe br_netfilter 30ExecStartPre=-/sbin/modprobe br_netfilter
25ExecStartPre=-/sbin/modprobe overlay 31ExecStartPre=-/sbin/modprobe overlay
26ExecStart=/usr/local/bin/k3s server 32ExecStart=/usr/local/bin/k3s server
27 33# 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
35# services and containers
36ExecStopPost=/bin/sh -c "if systemctl is-system-running | grep -i \
37 'stopping'; then /usr/local/bin/k3s-killall.sh; fi"
diff --git a/recipes-containers/k3s/k3s_git.bb b/recipes-containers/k3s/k3s_git.bb
index 68c66ec0..adccb087 100644
--- a/recipes-containers/k3s/k3s_git.bb
+++ b/recipes-containers/k3s/k3s_git.bb
@@ -11,6 +11,7 @@ SRC_URI = "git://github.com/rancher/k3s.git;branch=release-1.21;name=k3s \
11 file://k3s-clean \ 11 file://k3s-clean \
12 file://cni-containerd-net.conf \ 12 file://cni-containerd-net.conf \
13 file://0001-Finding-host-local-in-usr-libexec.patch;patchdir=src/import \ 13 file://0001-Finding-host-local-in-usr-libexec.patch;patchdir=src/import \
14 file://k3s-killall.sh \
14 " 15 "
15SRC_URI[k3s.md5sum] = "363d3a08dc0b72ba6e6577964f6e94a5" 16SRC_URI[k3s.md5sum] = "363d3a08dc0b72ba6e6577964f6e94a5"
16SRCREV_k3s = "aa5a0a8c783a8a4475b727a04d6594c0fea09253" 17SRCREV_k3s = "aa5a0a8c783a8a4475b727a04d6594c0fea09253"
@@ -60,6 +61,7 @@ do_install() {
60 # ln -sr "${D}/${BIN_PREFIX}/bin/k3s" "${D}${BIN_PREFIX}/bin/ctr" 61 # ln -sr "${D}/${BIN_PREFIX}/bin/k3s" "${D}${BIN_PREFIX}/bin/ctr"
61 ln -sr "${D}/${BIN_PREFIX}/bin/k3s" "${D}${BIN_PREFIX}/bin/kubectl" 62 ln -sr "${D}/${BIN_PREFIX}/bin/k3s" "${D}${BIN_PREFIX}/bin/kubectl"
62 install -m 755 "${WORKDIR}/k3s-clean" "${D}${BIN_PREFIX}/bin" 63 install -m 755 "${WORKDIR}/k3s-clean" "${D}${BIN_PREFIX}/bin"
64 install -m 755 "${WORKDIR}/k3s-killall.sh" "${D}${BIN_PREFIX}/bin"
63 65
64 if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then 66 if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
65 install -D -m 0644 "${WORKDIR}/k3s.service" "${D}${systemd_system_unitdir}/k3s.service" 67 install -D -m 0644 "${WORKDIR}/k3s.service" "${D}${systemd_system_unitdir}/k3s.service"