mirror of https://github.com/easzlab/kubeasz.git
165 lines
5.0 KiB
YAML
165 lines
5.0 KiB
YAML
# to clean 'kube_node' nodes
|
|
- block:
|
|
- name: stop and disable kube_node service
|
|
service: name={{ item }} state=stopped enabled=no
|
|
with_items:
|
|
- kube-lb
|
|
- kubelet
|
|
- kube-proxy
|
|
ignore_errors: true
|
|
|
|
- name: umount kubelet filesystems
|
|
shell: "mount | grep '/var/lib/kubelet'| awk '{print $3}'|xargs umount || exit 0"
|
|
args:
|
|
warn: false
|
|
ignore_errors: true
|
|
|
|
- name: remove files and dirs of 'kube_node' nodes
|
|
file: name={{ item }} state=absent
|
|
with_items:
|
|
- "/var/lib/kubelet/"
|
|
- "/var/lib/kube-proxy/"
|
|
- "/etc/systemd/system/kube-lb.service"
|
|
- "/etc/systemd/system/kubelet.service"
|
|
- "/etc/systemd/system/kube-proxy.service"
|
|
- "/etc/kube-lb/"
|
|
- "/etc/kubernetes/"
|
|
- "/root/.kube/config"
|
|
|
|
# to clean container runtime and networking
|
|
- block:
|
|
- name: to check if container 'kubeasz' is running
|
|
shell: 'docker ps|grep kubeasz || echo "NOT FOUND"'
|
|
register: install_info
|
|
|
|
- block:
|
|
- 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: umount docker filesystem-1
|
|
mount: path=/var/run/docker/netns/default state=unmounted
|
|
|
|
- name: umount docker filesystem-2
|
|
mount: path=/var/lib/docker/overlay state=unmounted
|
|
|
|
- name: umount docker filesystem-3
|
|
shell: "echo /var/lib/docker/overlay2/*/merged|xargs umount || exit 0"
|
|
args:
|
|
warn: false
|
|
ignore_errors: true
|
|
|
|
- name: umount docker filesystem-4
|
|
shell: "echo /var/lib/docker/containers/*/mounts/shm|xargs umount || exit 0"
|
|
args:
|
|
warn: false
|
|
ignore_errors: true
|
|
|
|
- name: umount docker filesystem-5
|
|
shell: "echo /var/run/docker/netns/*|xargs umount || exit 0"
|
|
args:
|
|
warn: false
|
|
ignore_errors: true
|
|
|
|
- name: remove files and dirs
|
|
file: name={{ item }} state=absent
|
|
with_items:
|
|
- "/var/lib/docker/"
|
|
- "/var/lib/dockershim/"
|
|
- "/var/run/docker/"
|
|
- "/etc/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: "'kubeasz' not in install_info.stdout"
|
|
ignore_errors: true
|
|
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/"
|
|
ignore_errors: true
|
|
when: CONTAINER_RUNTIME == 'containerd'
|
|
|
|
- name: remove files and dirs2
|
|
file: name={{ item }} state=absent
|
|
with_items:
|
|
- "/etc/cni/"
|
|
- "/run/flannel/"
|
|
- "/etc/calico/"
|
|
- "/var/run/calico/"
|
|
- "/var/lib/calico/"
|
|
- "/var/log/calico/"
|
|
- "/etc/cilium/"
|
|
- "/var/run/cilium/"
|
|
- "/sys/fs/bpf/tc/"
|
|
- "/var/lib/cni/"
|
|
- "/var/lib/kube-router/"
|
|
- "/opt/kube/kube-ovn/"
|
|
- "/var/run/openvswitch/"
|
|
- "/etc/origin/openvswitch/"
|
|
- "/etc/openvswitch/"
|
|
- "/var/log/openvswitch/"
|
|
- "/var/run/ovn/"
|
|
- "/etc/origin/ovn/"
|
|
- "/etc/ovn/"
|
|
- "/var/log/ovn/"
|
|
|
|
# - name: cleanup networks1
|
|
# shell: "ip link del tunl0; \
|
|
# ip link del flannel.1; \
|
|
# ip link del cni0; \
|
|
# ip link del mynet0; \
|
|
# ip link del kube-bridge; \
|
|
# ip link del dummy0; \
|
|
# ip link del kube-ipvs0; \
|
|
# ip link del cilium_net; \
|
|
# ip link del cilium_vxlan; \
|
|
# ip link del ovn0; \
|
|
# ip link del ovs-system"
|
|
# ignore_errors: true
|
|
#
|
|
# - name: cleanup networks2
|
|
# shell: "systemctl restart networking; \
|
|
# systemctl restart network"
|
|
# ignore_errors: true
|
|
#
|
|
# - name: cleanup 'calico' routes
|
|
# 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
|
|
#
|
|
# - name: cleanup 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"
|
|
|
|
when: "inventory_hostname in groups['kube_master'] or inventory_hostname in groups['kube_node']"
|