-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.sh
146 lines (123 loc) · 3.7 KB
/
cleanup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
set -o nounset
set -o pipefail
OPT=$1
function kubeworkz_uninstall() {
clog info "uninstalling kubeworkz"
clog debug "remove kubeworkz files"
rm -rf /etc/kubeworkz
clog debug "uninstall kubeworkz helm chart release"
kubectl delete validatingwebhookconfigurations kubeworkz-validating-webhook-configuration warden-validating-webhook-configuration kubeworkz-monitoring-admission || true
kubectl delete cluster --all || true
helm uninstall kubeworkz -n kubeworkz-system || true
kubectl delete ns kubeworkz-system hnc-system kubeworkz-monitoring || true
clog warn "make sure namespace ingress-nginx has been terminated by: kubectl get ns ingress-nginx"
clog warn "manually delete monitoring if you do not need it by: kubectl delete ns kubeworkz-monitoring"
clog info "kubeworkz uninstall success"
}
function kubernetes_uninstall() {
clog info "uninstalling kubernetes"
clog debug "kubernetes reset"
kubeadm reset
rm -rf /root/.kube
clog debug "delete residual files of kubernetes"
rm -rf /etc/kubernetes/
rm -rf /var/lib/etcd
rm -rf /var/lib/cni/
clog debug "delete binaries of kubernetes"
rm /usr/local/bin/crictl
rm /usr/local/bin/kubeadm
rm /usr/local/bin/kubectl
rm /usr/local/bin/kubelet
rm /usr/local/bin/helm || true
clog info "kubernetes uninstall success"
}
function docker_uninstall() {
clog info "uninstalling docker"
clog debug "stop docker"
systemctl stop docker
clog debug "delete residual files of docker"
rm -rf /var/lib/docker
rm /etc/systemd/system/docker.service
rm /etc/docker/daemon.json
rm /usr/bin/docker
rm /usr/bin/dockerd
umount /var/run/docker/netns/default
rm -rf /var/run/docker
clog info "docker uninstall success"
}
function containerd_uninstall() {
clog info "uninstalling containerd"
systemctl disable containerd --now
rm -f /etc/crictl.yaml
rm -rf /etc/cni
rm -f /etc/systemd/system/containerd.service
rm -f /usr/local/sbin/runc
rm -f /usr/local/bin/containerd-shim-runc-v1
rm -f /usr/local/bin/critest
rm -f /usr/local/bin/ctr
rm -f /usr/local/bin/containerd-shim
rm -f /usr/local/bin/crictl
rm -f /usr/local/bin/containerd
rm -f /usr/local/bin/ctd-decoder
rm -f /usr/local/bin/containerd-stress
rm -f /usr/local/bin/containerd-shim-runc-v2
rm -rf /opt/cni
rm -rf /opt/containerd
rm -rf /etc/containerd
clog info "containerd uninstall success"
}
function cri_dockerd_uninstall() {
clog info "uninstalling cri_dockerd"
clog debug "stop cri_dockerd"
systemctl stop cri-docker.service
systemctl stop cri-docker.socket
clog debug "delete residual files of cri_dockerd"
rm -f /etc/systemd/system/cri-docker.socket
rm -f /etc/systemd/system/cri-docker.service
rm -f /usr/local/bin/cri-dockerd
clog info "cri_dockerd uninstall success"
}
function clog() {
TIMESTAMP=$(date +'%Y-%m-%d %H:%M:%S')
case "$1" in
debug)
echo -e "$TIMESTAMP \033[36mDEBUG\033[0m $2"
;;
info)
echo -e "$TIMESTAMP \033[32mINFO\033[0m $2"
;;
warn)
echo -e "$TIMESTAMP \033[33mWARN\033[0m $2"
;;
error)
echo -e "$TIMESTAMP \033[31mERROR\033[0m $2"
;;
*)
;;
esac
}
function main() {
case ${OPT} in
"kubeworkz") kubeworkz_uninstall
;;
"k8s") kubernetes_uninstall
;;
"docker") docker_uninstall
cri_dockerd_uninstall
;;
"containerd") containerd_uninstall
;;
"all")
kubeworkz_uninstall
kubernetes_uninstall
docker_uninstall
containerd_uninstall
cri_dockerd_uninstall
;;
*)
echo "unknown params, only support: 'kubeworkz','k8s','docker','containerd','all'"
;;
esac
}
main