2020-02-25 18:29:39 +01:00
|
|
|
#!/bin/sh
|
2020-02-26 21:05:38 +01:00
|
|
|
|
2020-02-25 18:29:39 +01:00
|
|
|
[ $(id -u) -eq 0 ] || exec sudo $0 $@
|
|
|
|
|
2020-10-19 21:32:53 +02:00
|
|
|
for bin in {{ k3s_node_data_dir | default('/var/lib/rancher/k3s') }}/data/**/bin/; do
|
2020-02-26 21:05:38 +01:00
|
|
|
[ -d "$bin" ] && export PATH=$bin:$PATH
|
2020-02-25 18:29:39 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
for service in /etc/systemd/system/k3s*.service; do
|
2020-02-26 21:05:38 +01:00
|
|
|
[ -s "$service" ] && systemctl stop "$(basename $service)"
|
2020-02-25 18:29:39 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
for service in /etc/init.d/k3s*; do
|
2020-02-26 21:05:38 +01:00
|
|
|
[ -x "$service" ] && "$service" stop
|
2020-02-25 18:29:39 +01:00
|
|
|
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() {
|
|
|
|
lsof | sed -e 's/^[^0-9]*//g; s/ */\t/g' | grep -w 'k3s/data/[^/]*/bin/containerd-shim' | cut -f1 | sort -n -u
|
|
|
|
}
|
|
|
|
|
|
|
|
killtree $({ set +x; } 2>/dev/null; getshims; set -x)
|
|
|
|
|
|
|
|
do_unmount() {
|
|
|
|
{ set +x; } 2>/dev/null
|
|
|
|
MOUNTS=
|
|
|
|
while read ignore mount ignore; do
|
|
|
|
MOUNTS="$mount\n$MOUNTS"
|
|
|
|
done </proc/self/mounts
|
|
|
|
MOUNTS=$(printf $MOUNTS | grep "^$1" | sort -r)
|
|
|
|
if [ -n "${MOUNTS}" ]; then
|
|
|
|
set -x
|
|
|
|
umount ${MOUNTS}
|
|
|
|
else
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
do_unmount '/run/k3s'
|
2020-10-19 21:32:53 +02:00
|
|
|
do_unmount '{{ k3s_node_data_dir | default('/var/lib/rancher/k3s') }}'
|
2020-02-25 18:29:39 +01:00
|
|
|
do_unmount '/var/lib/kubelet/pods'
|
|
|
|
do_unmount '/run/netns/cni-'
|
|
|
|
|
|
|
|
# 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
|
2020-02-26 21:05:38 +01:00
|
|
|
|
2020-02-25 18:29:39 +01:00
|
|
|
ip link delete cni0
|
|
|
|
ip link delete flannel.1
|
2020-02-26 21:05:38 +01:00
|
|
|
[ -d /var/lib/cni ] && rm -rf /var/lib/cni/
|
|
|
|
iptables-save | grep -v KUBE- | grep -v CNI- | iptables-restore
|