kubeasz/99.clean.yml

108 lines
3.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 警告此脚本将清理真个K8S集群包括所有POD、ETCD数据等
# 请三思后运行此脚本 ansible-playbook 99.clean.yml
- hosts: kube-node
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/"
- "/etc/kubernetes/"
- "/etc/systemd/system/kubelet.service"
- "/etc/systemd/system/kube-proxy.service"
# - "/root/local/bin/"
- hosts: kube-master
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"
- "/etc/kubernetes/"
- hosts:
- kube-cluster
- deploy
tasks:
- name: stop calico-node service
shell: "systemctl stop calico-node docker"
ignore_errors: true
# 因为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
- name: 清理目录和文件
file: name={{ item }} state=absent
with_items:
- "/etc/cni/"
- "/root/.kube/"
- "/etc/calico/"
- "/var/run/calico/"
- "/var/log/calico/"
- "/var/lib/docker/"
- "/var/run/docker/"
- "/etc/systemd/system/calico-node.service"
- "/etc/systemd/system/docker.service"
- "/etc/systemd/system/docker.service.requires/"
- name: 清理 iptables
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"
- name: 清理网络
shell: "ip link del docker0; ip link del tunl0; systemctl restart networking"
ignore_errors: true
- 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"
- 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"
ignore_errors: true