2018-09-29 09:06:19 +08:00
|
|
|
# WARNING: This playbook will erase the entire k8s-cluster, include PODs, ETCD data etc.
|
|
|
|
# Make sure you know what you are doing.
|
2017-11-30 00:21:32 +08:00
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
# to clean 'kube-node' nodes
|
2017-12-26 15:52:35 +08:00
|
|
|
- hosts:
|
2018-03-16 18:23:34 +08:00
|
|
|
- kube-master
|
2017-12-26 15:52:35 +08:00
|
|
|
- kube-node
|
2017-11-30 00:21:32 +08:00
|
|
|
tasks:
|
2018-07-05 16:00:44 +08:00
|
|
|
- name: stop and disable kube-node service
|
|
|
|
service: name={{ item }} state=stopped enabled=no
|
|
|
|
with_items:
|
|
|
|
- kubelet
|
|
|
|
- kube-proxy
|
2017-11-30 00:21:32 +08:00
|
|
|
ignore_errors: true
|
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: umount kubelet filesystems
|
2019-05-19 08:51:01 +08:00
|
|
|
shell: "mount | grep '/var/lib/kubelet'| awk '{print $3}'|xargs umount || exit 0"
|
2018-10-11 11:01:15 +08:00
|
|
|
args:
|
|
|
|
warn: false
|
2017-11-30 00:21:32 +08:00
|
|
|
ignore_errors: true
|
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: remove files and dirs of 'kube-node' nodes
|
2017-11-30 00:21:32 +08:00
|
|
|
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-05-06 23:10:14 +08:00
|
|
|
- "/opt/kube/kube-system/"
|
2017-11-30 00:21:32 +08:00
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
# to clean 'kube-master' nodes
|
2018-03-18 22:51:05 +08:00
|
|
|
- hosts:
|
|
|
|
- kube-master
|
2017-11-30 00:21:32 +08:00
|
|
|
tasks:
|
2018-07-05 16:00:44 +08:00
|
|
|
- name: stop and disable kube-master service
|
|
|
|
service: name={{ item }} state=stopped enabled=no
|
|
|
|
with_items:
|
|
|
|
- kube-apiserver
|
|
|
|
- kube-controller-manager
|
|
|
|
- kube-scheduler
|
2017-11-30 00:21:32 +08:00
|
|
|
ignore_errors: true
|
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: remove files and dirs of 'kube-master' nodes
|
2017-11-30 00:21:32 +08:00
|
|
|
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"
|
|
|
|
|
2019-05-19 08:51:01 +08:00
|
|
|
# to clean container runtime and networking
|
2017-12-03 22:32:53 +08:00
|
|
|
- hosts:
|
2018-03-16 18:23:34 +08:00
|
|
|
- kube-master
|
2018-03-02 08:40:29 +08:00
|
|
|
- kube-node
|
2017-11-12 14:54:20 +08:00
|
|
|
tasks:
|
2019-05-19 08:51:01 +08:00
|
|
|
- block:
|
2019-05-27 00:04:00 +08:00
|
|
|
- name: to check if container 'kubeasz' is running
|
2019-05-19 08:51:01 +08:00
|
|
|
shell: 'docker ps|grep kubeasz || echo "NOT FOUND"'
|
|
|
|
register: install_info
|
|
|
|
|
2019-05-27 00:04:00 +08:00
|
|
|
- name: fail info
|
|
|
|
fail: msg="you CAN NOT delete dockerd, because container 'kubeasz' is running!"
|
|
|
|
when: "'kubeasz' in install_info.stdout"
|
|
|
|
|
2019-05-19 08:51:01 +08:00
|
|
|
- name: stop and disable docker service
|
|
|
|
service:
|
|
|
|
name: docker
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
# as k8s-network-plugins use host-network, '/var/run/docker/netns/default' must be umounted
|
|
|
|
- name: unmount docker filesystem-1
|
|
|
|
mount: path=/var/run/docker/netns/default state=unmounted
|
|
|
|
|
|
|
|
- name: unmount docker filesystem-2
|
|
|
|
mount: path=/var/lib/docker/overlay state=unmounted
|
|
|
|
|
|
|
|
- name: remove files and dirs
|
|
|
|
file: name={{ item }} state=absent
|
|
|
|
with_items:
|
|
|
|
- "/var/lib/docker/"
|
|
|
|
- "/var/run/docker/"
|
|
|
|
- "/etc/systemd/system/docker.service"
|
|
|
|
- "/etc/systemd/system/docker.service.requires/"
|
|
|
|
- "/etc/systemd/system/docker.service.d/"
|
|
|
|
- "/etc/bash_completion.d/docker"
|
|
|
|
- "/usr/bin/docker"
|
|
|
|
when: CONTAINER_RUNTIME == 'docker'
|
|
|
|
|
|
|
|
- block:
|
|
|
|
- name: stop and disable containerd service
|
|
|
|
service:
|
|
|
|
name: containerd
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: umount containerd filesystems
|
|
|
|
shell: "mount | grep 'containerd/io.containerd'| awk '{print $3}'|xargs umount || exit 0"
|
|
|
|
args:
|
|
|
|
warn: false
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: remove files and dirs
|
|
|
|
file: name={{ item }} state=absent
|
|
|
|
with_items:
|
|
|
|
- "/etc/containerd/"
|
|
|
|
- "/etc/crictl.yaml"
|
|
|
|
- "/etc/systemd/system/containerd.service"
|
|
|
|
- "/opt/containerd/"
|
|
|
|
- "/var/lib/containerd/"
|
|
|
|
- "/var/run/containerd/"
|
|
|
|
when: CONTAINER_RUNTIME == 'containerd'
|
2019-02-28 16:06:26 +08:00
|
|
|
|
|
|
|
- name: remove files and dirs2
|
2017-11-12 14:54:20 +08:00
|
|
|
file: name={{ item }} state=absent
|
|
|
|
with_items:
|
|
|
|
- "/etc/cni/"
|
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/"
|
2018-08-11 15:26:44 +08:00
|
|
|
- "/var/lib/calico/"
|
2017-11-12 14:54:20 +08:00
|
|
|
- "/var/log/calico/"
|
2018-08-05 16:12:32 +08:00
|
|
|
- "/etc/cilium/"
|
|
|
|
- "/var/run/cilium/"
|
|
|
|
- "/sys/fs/bpf/tc/"
|
2018-06-17 10:49:51 +08:00
|
|
|
- "/var/lib/cni/"
|
2018-06-14 21:38:39 +08:00
|
|
|
- "/var/lib/kube-router/"
|
|
|
|
- "/opt/kube/kube-system/"
|
2019-05-22 11:17:42 +08:00
|
|
|
- "/var/run/openvswitch/"
|
|
|
|
- "/etc/origin/openvswitch/"
|
|
|
|
- "/etc/openvswitch/"
|
|
|
|
- "/var/log/openvswitch/"
|
2017-11-12 14:54:20 +08:00
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: cleanup 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
|
|
|
|
2019-02-28 16:06:26 +08:00
|
|
|
- name: cleanup networks1
|
|
|
|
shell: "ip link del tunl0; \
|
2017-12-31 10:25:56 +08:00
|
|
|
ip link del flannel.1; \
|
|
|
|
ip link del cni0; \
|
2018-01-05 23:05:22 +08:00
|
|
|
ip link del mynet0; \
|
2018-06-14 23:34:03 +08:00
|
|
|
ip link del kube-bridge; \
|
|
|
|
ip link del dummy0; \
|
2018-07-13 10:00:12 +08:00
|
|
|
ip link del kube-ipvs0; \
|
2018-08-11 22:37:57 +08:00
|
|
|
ip link del cilium_net; \
|
2019-05-22 11:17:42 +08:00
|
|
|
ip link del cilium_vxlan; \
|
|
|
|
ip link del ovn0; \
|
|
|
|
ip link del ovs-system"
|
2019-02-28 16:06:26 +08:00
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: cleanup networks2
|
|
|
|
shell: "ip link del docker0; \
|
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-09-29 09:06:19 +08:00
|
|
|
- name: cleanup 'calico' routes
|
2019-05-31 23:07:00 +08:00
|
|
|
shell: "for rt in `ip route|grep bird|sed 's/blackhole //'|awk '{print $1}'`;do ip route del $rt;done;"
|
2018-03-28 21:05:21 +08:00
|
|
|
when: "CLUSTER_NETWORK == 'calico'"
|
|
|
|
ignore_errors: true
|
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
# to clean 'etcd' nodes
|
2017-11-11 19:14:21 +08:00
|
|
|
- hosts: etcd
|
|
|
|
tasks:
|
2018-07-05 16:00:44 +08:00
|
|
|
- name: stop and disable etcd service
|
|
|
|
service:
|
|
|
|
name: etcd
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
2017-11-11 19:14:21 +08:00
|
|
|
ignore_errors: true
|
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: remove files and dirs
|
2017-11-11 19:14:21 +08:00
|
|
|
file: name={{ item }} state=absent
|
|
|
|
with_items:
|
|
|
|
- "/var/lib/etcd"
|
|
|
|
- "/etc/etcd/"
|
2018-07-23 16:58:12 +08:00
|
|
|
- "/backup/k8s"
|
2017-11-11 19:14:21 +08:00
|
|
|
- "/etc/systemd/system/etcd.service"
|
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
# to clean 'lb' nodes
|
2019-02-19 16:38:10 +08:00
|
|
|
- hosts:
|
2019-05-31 23:07:00 +08:00
|
|
|
- kube-node
|
2019-02-19 16:38:10 +08:00
|
|
|
- ex-lb
|
2017-11-11 19:14:21 +08:00
|
|
|
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
|
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: remove files and dirs
|
2017-11-11 19:14:21 +08:00
|
|
|
file: name={{ item }} state=absent
|
|
|
|
with_items:
|
|
|
|
- "/etc/haproxy"
|
|
|
|
- "/etc/keepalived"
|
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
# to clean ntp, certs and keys, env path
|
2018-08-31 22:58:44 +08:00
|
|
|
- hosts:
|
|
|
|
- kube-master
|
|
|
|
- kube-node
|
|
|
|
- etcd
|
2019-05-30 21:37:01 +08:00
|
|
|
- ex-lb
|
2018-03-02 10:44:55 +08:00
|
|
|
tasks:
|
2019-05-30 21:37:01 +08:00
|
|
|
- block:
|
|
|
|
- name: stop and disable chrony in Ubuntu
|
|
|
|
service: name=chrony state=stopped enabled=no
|
|
|
|
ignore_errors: true
|
|
|
|
when: 'ansible_distribution in ["Ubuntu","Debian"]'
|
2018-10-11 11:01:15 +08:00
|
|
|
|
2019-05-30 21:37:01 +08:00
|
|
|
- name: stop and disable chronyd in CentOS/RedHat
|
|
|
|
service: name=chronyd state=stopped enabled=no
|
|
|
|
ignore_errors: true
|
|
|
|
when: 'ansible_distribution in ["CentOS","RedHat","Amazon"]'
|
|
|
|
when: "groups['chrony']|length > 0"
|
2018-08-17 12:27:25 +08:00
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: clean certs and keys
|
2018-03-02 08:40:29 +08:00
|
|
|
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 }}"
|
2019-03-04 11:23:12 +08:00
|
|
|
- "/root/.kube/config"
|
2018-03-09 22:02:55 +08:00
|
|
|
- "/etc/docker/"
|
2018-05-03 01:49:42 +08:00
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: clean 'ENV PATH'
|
2018-05-04 15:27:46 +08:00
|
|
|
lineinfile:
|
2018-05-06 09:08:09 +08:00
|
|
|
dest: ~/.bashrc
|
2018-05-04 15:27:46 +08:00
|
|
|
state: absent
|
2018-07-02 16:48:26 +08:00
|
|
|
regexp: '{{ item }}'
|
|
|
|
with_items:
|
|
|
|
- 'kubeasz'
|
2019-05-19 08:51:01 +08:00
|
|
|
- 'helm completion'
|
2018-07-02 16:48:26 +08:00
|
|
|
- 'kubectl completion'
|
2019-05-19 08:51:01 +08:00
|
|
|
- 'crictl completion'
|
2019-03-16 17:32:43 +08:00
|
|
|
- 'HELM_TLS_ENABLE'
|