summarylogtreecommitdiffstats
path: root/k3s-killall.sh
diff options
context:
space:
mode:
authorThomas Scheller2024-01-29 22:04:07 +0100
committerThomas Scheller2024-01-29 22:04:07 +0100
commitc105bdab8e70507eea76acf9fbfc11f9d8112a31 (patch)
treef6db391f1c798784183dff14a61db7766373f4d9 /k3s-killall.sh
downloadaur-c105bdab8e70507eea76acf9fbfc11f9d8112a31.tar.gz
Initial
Diffstat (limited to 'k3s-killall.sh')
-rwxr-xr-xk3s-killall.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/k3s-killall.sh b/k3s-killall.sh
new file mode 100755
index 000000000000..603a39ae8205
--- /dev/null
+++ b/k3s-killall.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+[ $(id -u) -eq 0 ] || exec sudo $0 $@
+for bin in /var/lib/rancher/k3s/data/**/bin/; do
+ [ -d $bin ] && export PATH=$PATH:$bin:$bin/aux
+done
+set -x
+for service in /etc/systemd/system/k3s*.service; do
+ [ -s $service ] && systemctl stop $(basename $service)
+done
+for service in /etc/init.d/k3s*; do
+ [ -x $service ] && $service stop
+done
+pschildren() {
+ ps -e -o ppid= -o pid= | \
+ sed -e 's/^\s*//g; s/\s\s*/\t/g;' | \
+ grep -w "^$1" | \
+ cut -f2
+}
+pstree() {
+ for pid in $@; do
+ echo $pid
+ for child in $(pschildren $pid); do
+ pstree $child
+ done
+ done
+}
+killtree() {
+ kill -9 $(
+ { set +x; } 2>/dev/null;
+ pstree $@;
+ set -x;
+ ) 2>/dev/null
+}
+getshims() {
+ ps -e -o pid= -o args= | sed -e 's/^ *//; s/\s\s*/\t/;' | grep -w 'k3s/data/[^/]*/bin/containerd-shim' | cut -f1
+}
+killtree $({ set +x; } 2>/dev/null; getshims; set -x)
+do_unmount_and_remove() {
+ awk -v path="$1" '$2 ~ ("^" path) { print $2 }' /proc/self/mounts | sort -r | xargs -r -t -n 1 sh -c 'umount "$0" && rm -rf "$0"'
+}
+do_unmount_and_remove '/run/k3s'
+do_unmount_and_remove '/var/lib/rancher/k3s'
+do_unmount_and_remove '/var/lib/kubelet/pods'
+do_unmount_and_remove '/run/netns/cni-'
+# Remove CNI namespaces
+ip netns show 2>/dev/null | grep cni- | xargs -r -t -n 1 ip netns delete
+# Delete network interface(s) that match 'master cni0'
+ip link show 2>/dev/null | grep 'master cni0' | while read ignore iface ignore; do
+ iface=${iface%%@*}
+ [ -z "$iface" ] || ip link delete $iface
+done
+ip link delete cni0
+ip link delete flannel.1
+rm -rf /var/lib/cni/
+iptables-save | grep -v KUBE- | grep -v CNI- | iptables-restore