2017-12-26 15:52:35 +08:00
|
|
|
|
# 警告:此脚本将清理整个K8S集群,包括所有POD、ETCD数据等
|
2017-11-26 09:34:33 +08:00
|
|
|
|
# 请三思后运行此脚本 ansible-playbook 99.clean.yml
|
2017-11-30 00:21:32 +08:00
|
|
|
|
|
2018-03-02 18:17:58 +08:00
|
|
|
|
# 清理 kube-node 相关服务
|
2017-12-26 15:52:35 +08:00
|
|
|
|
- hosts:
|
2018-03-16 18:23:34 +08:00
|
|
|
|
- kube-master
|
2018-03-18 22:51:05 +08:00
|
|
|
|
- new-master
|
2017-12-26 15:52:35 +08:00
|
|
|
|
- kube-node
|
|
|
|
|
- new-node
|
2017-11-30 00:21:32 +08:00
|
|
|
|
tasks:
|
|
|
|
|
- name: stop kube-node service
|
|
|
|
|
shell: "systemctl stop kubelet kube-proxy"
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
|
|
- name: umount kubelet 挂载的目录
|
|
|
|
|
shell: "mount | grep '/var/lib/kubelet'| awk '{print $3}'|xargs umount"
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
|
|
- name: 清理目录和文件
|
|
|
|
|
file: name={{ item }} state=absent
|
|
|
|
|
with_items:
|
|
|
|
|
- "/var/lib/kubelet/"
|
2018-01-02 22:12:51 +08:00
|
|
|
|
- "/var/lib/kube-proxy/"
|
2017-11-30 00:21:32 +08:00
|
|
|
|
- "/etc/systemd/system/kubelet.service"
|
|
|
|
|
- "/etc/systemd/system/kube-proxy.service"
|
2018-03-16 18:23:34 +08:00
|
|
|
|
- "/root/local/kube-system/"
|
2017-11-30 00:21:32 +08:00
|
|
|
|
|
2018-03-02 18:17:58 +08:00
|
|
|
|
# 清理 kube-master 相关
|
2018-03-18 22:51:05 +08:00
|
|
|
|
- hosts:
|
|
|
|
|
- kube-master
|
|
|
|
|
- new-master
|
2017-11-30 00:21:32 +08:00
|
|
|
|
tasks:
|
|
|
|
|
- name: stop kube-master service
|
|
|
|
|
shell: "systemctl stop kube-apiserver kube-controller-manager kube-scheduler"
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
|
|
- name: 清理目录和文件
|
|
|
|
|
file: name={{ item }} state=absent
|
|
|
|
|
with_items:
|
|
|
|
|
- "/var/run/kubernetes"
|
|
|
|
|
- "/etc/systemd/system/kube-apiserver.service"
|
|
|
|
|
- "/etc/systemd/system/kube-controller-manager.service"
|
|
|
|
|
- "/etc/systemd/system/kube-scheduler.service"
|
|
|
|
|
|
2018-03-02 18:17:58 +08:00
|
|
|
|
# 清理集群docker服务、网络相关
|
2017-12-03 22:32:53 +08:00
|
|
|
|
- hosts:
|
2018-03-16 18:23:34 +08:00
|
|
|
|
- kube-master
|
2018-03-18 22:51:05 +08:00
|
|
|
|
- new-master
|
2018-03-02 08:40:29 +08:00
|
|
|
|
- kube-node
|
2017-12-26 15:52:35 +08:00
|
|
|
|
- new-node
|
2017-11-12 14:54:20 +08:00
|
|
|
|
tasks:
|
2018-01-02 22:12:51 +08:00
|
|
|
|
- name: stop docker service
|
|
|
|
|
shell: "systemctl stop docker"
|
2017-11-12 14:54:20 +08:00
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
2017-11-12 16:17:50 +08:00
|
|
|
|
# 因为calico-kube-controller使用了host网络,相当于使用了docker -net=host,需要
|
|
|
|
|
# 卸载 /var/run/docker/netns/default
|
|
|
|
|
- name: 卸载docker 相关fs1
|
|
|
|
|
mount: path=/var/run/docker/netns/default state=unmounted
|
|
|
|
|
|
|
|
|
|
- name: 卸载docker 相关fs2
|
|
|
|
|
mount: path=/var/lib/docker/overlay state=unmounted
|
|
|
|
|
|
2017-11-12 14:54:20 +08:00
|
|
|
|
- name: 清理目录和文件
|
|
|
|
|
file: name={{ item }} state=absent
|
|
|
|
|
with_items:
|
|
|
|
|
- "/etc/cni/"
|
2017-12-03 22:32:53 +08:00
|
|
|
|
- "/root/.kube/"
|
2018-01-02 22:12:51 +08:00
|
|
|
|
- "/run/flannel/"
|
2017-11-22 12:34:51 +08:00
|
|
|
|
- "/etc/calico/"
|
2017-11-12 14:54:20 +08:00
|
|
|
|
- "/var/run/calico/"
|
|
|
|
|
- "/var/log/calico/"
|
|
|
|
|
- "/var/lib/docker/"
|
|
|
|
|
- "/var/run/docker/"
|
2018-03-02 18:17:58 +08:00
|
|
|
|
- "/root/local/kube-system/"
|
2017-11-12 14:54:20 +08:00
|
|
|
|
- "/etc/systemd/system/calico-node.service"
|
|
|
|
|
- "/etc/systemd/system/docker.service"
|
2017-11-26 09:34:33 +08:00
|
|
|
|
- "/etc/systemd/system/docker.service.requires/"
|
2017-11-12 14:54:20 +08:00
|
|
|
|
|
|
|
|
|
- name: 清理 iptables
|
2017-11-28 23:27:38 +08:00
|
|
|
|
shell: "iptables -F && iptables -X \
|
|
|
|
|
&& iptables -F -t nat && iptables -X -t nat \
|
|
|
|
|
&& iptables -F -t raw && iptables -X -t raw \
|
|
|
|
|
&& iptables -F -t mangle && iptables -X -t mangle"
|
2017-11-12 14:54:20 +08:00
|
|
|
|
|
|
|
|
|
- name: 清理网络
|
2017-12-31 10:25:56 +08:00
|
|
|
|
shell: "ip link del docker0; \
|
|
|
|
|
ip link del tunl0; \
|
|
|
|
|
ip link del flannel.1; \
|
|
|
|
|
ip link del cni0; \
|
2018-01-05 23:05:22 +08:00
|
|
|
|
ip link del mynet0; \
|
2017-12-31 10:25:56 +08:00
|
|
|
|
systemctl restart networking; \
|
|
|
|
|
systemctl restart network"
|
2017-11-12 14:54:20 +08:00
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
2018-03-28 21:05:21 +08:00
|
|
|
|
- name: 清理calico残留路由
|
|
|
|
|
shell: "for rt in `ip route|grep bird|sed 's/blackhole//'|awk '{print $1}'`;do ip route del $rt;done;"
|
|
|
|
|
when: "CLUSTER_NETWORK == 'calico'"
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
2018-03-02 18:17:58 +08:00
|
|
|
|
# 清理etcd 集群相关
|
2017-11-11 19:14:21 +08:00
|
|
|
|
- hosts: etcd
|
|
|
|
|
tasks:
|
|
|
|
|
- name: stop etcd service
|
|
|
|
|
shell: systemctl stop etcd
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
|
|
- name: 清理目录和文件
|
|
|
|
|
file: name={{ item }} state=absent
|
|
|
|
|
with_items:
|
|
|
|
|
- "/var/lib/etcd"
|
|
|
|
|
- "/etc/etcd/"
|
|
|
|
|
- "/etc/systemd/system/etcd.service"
|
|
|
|
|
|
2018-03-02 18:17:58 +08:00
|
|
|
|
# 清理负载均衡相关
|
2017-11-11 19:14:21 +08:00
|
|
|
|
- hosts: lb
|
|
|
|
|
tasks:
|
|
|
|
|
- name: stop keepalived service
|
|
|
|
|
shell: systemctl disable keepalived && systemctl stop keepalived
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
|
|
- name: stop haproxy service
|
|
|
|
|
shell: systemctl disable haproxy && systemctl stop haproxy
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
|
|
- name: 清理LB 配置文件目录
|
|
|
|
|
file: name={{ item }} state=absent
|
|
|
|
|
with_items:
|
|
|
|
|
- "/etc/haproxy"
|
|
|
|
|
- "/etc/keepalived"
|
|
|
|
|
|
2018-03-18 22:51:05 +08:00
|
|
|
|
- hosts: all
|
2018-03-02 10:44:55 +08:00
|
|
|
|
tasks:
|
2018-03-02 08:40:29 +08:00
|
|
|
|
- name: 清理证书目录和文件
|
|
|
|
|
file: name={{ item }} state=absent
|
|
|
|
|
with_items:
|
2018-03-09 22:02:55 +08:00
|
|
|
|
- "/etc/kubernetes/"
|
2018-03-02 08:40:29 +08:00
|
|
|
|
- "{{ ca_dir }}"
|
2018-03-09 22:02:55 +08:00
|
|
|
|
- "/root/.kube/"
|
|
|
|
|
- "/etc/docker/"
|