111
|
1 #!/bin/sh
|
|
2 [ $(id -u) -eq 0 ] || exec sudo $0 $@
|
|
3
|
|
4 for bin in /var/lib/rancher/k3s/data/**/bin/; do
|
|
5 [ -d $bin ] && export PATH=$PATH:$bin:$bin/aux
|
|
6 done
|
|
7
|
|
8 set -x
|
|
9
|
|
10 for service in /etc/systemd/system/k3s*.service; do
|
|
11 [ -s $service ] && systemctl stop $(basename $service)
|
|
12 done
|
|
13
|
|
14 for service in /etc/init.d/k3s*; do
|
|
15 [ -x $service ] && $service stop
|
|
16 done
|
|
17
|
|
18 pschildren() {
|
|
19 ps -e -o ppid= -o pid= | \
|
|
20 sed -e 's/^\s*//g; s/\s\s*/\t/g;' | \
|
|
21 grep -w "^$1" | \
|
|
22 cut -f2
|
|
23 }
|
|
24
|
|
25 pstree() {
|
|
26 for pid in $@; do
|
|
27 echo $pid
|
|
28 for child in $(pschildren $pid); do
|
|
29 pstree $child
|
|
30 done
|
|
31 done
|
|
32 }
|
|
33
|
|
34 killtree() {
|
|
35 kill -9 $(
|
|
36 { set +x; } 2>/dev/null;
|
|
37 pstree $@;
|
|
38 set -x;
|
|
39 ) 2>/dev/null
|
|
40 }
|
|
41
|
|
42 getshims() {
|
|
43 ps -e -o pid= -o args= | sed -e 's/^ *//; s/\s\s*/\t/;' | grep -w 'k3s/data/[^/]*/bin/containerd-shim' | cut -f1
|
|
44 }
|
|
45
|
|
46 killtree $({ set +x; } 2>/dev/null; getshims; set -x)
|
|
47
|
|
48 do_unmount_and_remove() {
|
|
49 set +x
|
|
50 while read -r _ path _; do
|
|
51 case "$path" in $1*) echo "$path" ;; esac
|
|
52 done < /proc/self/mounts | sort -r | xargs -r -t -n 1 sh -c 'umount "$0" && rm -rf "$0"'
|
|
53 set -x
|
|
54 }
|
|
55
|
|
56 do_unmount_and_remove '/run/k3s'
|
|
57 do_unmount_and_remove '/var/lib/rancher/k3s'
|
|
58 do_unmount_and_remove '/var/lib/kubelet/pods'
|
|
59 do_unmount_and_remove '/var/lib/kubelet/plugins'
|
|
60 do_unmount_and_remove '/run/netns/cni-'
|
|
61
|
|
62 # Remove CNI namespaces
|
|
63 ip netns show 2>/dev/null | grep cni- | xargs -r -t -n 1 ip netns delete
|
|
64
|
|
65 # Delete network interface(s) that match 'master cni0'
|
|
66 ip link show 2>/dev/null | grep 'master cni0' | while read ignore iface ignore; do
|
|
67 iface=${iface%%@*}
|
|
68 [ -z "$iface" ] || ip link delete $iface
|
|
69 done
|
|
70 ip link delete cni0
|
|
71 ip link delete flannel.1
|
|
72 ip link delete flannel-v6.1
|
|
73 ip link delete kube-ipvs0
|
|
74 rm -rf /var/lib/cni/
|
|
75 iptables-save | grep -v KUBE- | grep -v CNI- | grep -v flannel | iptables-restore
|
|
76 ip6tables-save | grep -v KUBE- | grep -v CNI- | grep -v flannel | ip6tables-restore
|