更新清理脚本支持containerd

pull/568/head
gjmzj 2019-05-19 08:51:01 +08:00
parent be3b7e090a
commit 1bf7636fa3
2 changed files with 132 additions and 79 deletions

View File

@ -14,7 +14,7 @@
ignore_errors: true ignore_errors: true
- name: umount kubelet filesystems - name: umount kubelet filesystems
shell: "mount | grep '/var/lib/kubelet'| awk '{print $3}'|xargs umount" shell: "mount | grep '/var/lib/kubelet'| awk '{print $3}'|xargs umount || exit 0"
args: args:
warn: false warn: false
ignore_errors: true ignore_errors: true
@ -48,11 +48,12 @@
- "/etc/systemd/system/kube-controller-manager.service" - "/etc/systemd/system/kube-controller-manager.service"
- "/etc/systemd/system/kube-scheduler.service" - "/etc/systemd/system/kube-scheduler.service"
# to clean docker service and networking # to clean container runtime and networking
- hosts: - hosts:
- kube-master - kube-master
- kube-node - kube-node
tasks: tasks:
- block:
- name: clean 'kube-router' stuff - name: clean 'kube-router' stuff
shell: "{{ bin_dir }}/docker run --privileged --net=host cloudnativelabs/kube-router --cleanup-config" shell: "{{ bin_dir }}/docker run --privileged --net=host cloudnativelabs/kube-router --cleanup-config"
ignore_errors: true ignore_errors: true
@ -90,6 +91,32 @@
- "/etc/bash_completion.d/docker" - "/etc/bash_completion.d/docker"
- "/usr/bin/docker" - "/usr/bin/docker"
when: "'kubeasz' not in install_info.stdout" when: "'kubeasz' not in install_info.stdout"
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'
- name: remove files and dirs2 - name: remove files and dirs2
file: name={{ item }} state=absent file: name={{ item }} state=absent
@ -112,7 +139,6 @@
&& iptables -F -t nat && iptables -X -t nat \ && iptables -F -t nat && iptables -X -t nat \
&& iptables -F -t raw && iptables -X -t raw \ && iptables -F -t raw && iptables -X -t raw \
&& iptables -F -t mangle && iptables -X -t mangle" && iptables -F -t mangle && iptables -X -t mangle"
when: "'kubeasz' not in install_info.stdout"
- name: cleanup networks1 - name: cleanup networks1
shell: "ip link del tunl0; \ shell: "ip link del tunl0; \
@ -131,7 +157,6 @@
systemctl restart networking; \ systemctl restart networking; \
systemctl restart network" systemctl restart network"
ignore_errors: true ignore_errors: true
when: "'kubeasz' not in install_info.stdout"
- name: cleanup 'calico' routes - name: cleanup 'calico' routes
shell: "for rt in `ip route|grep bird|sed 's/blackhole//'|awk '{print $1}'`;do ip route del $rt;done;" shell: "for rt in `ip route|grep bird|sed 's/blackhole//'|awk '{print $1}'`;do ip route del $rt;done;"
@ -210,6 +235,7 @@
regexp: '{{ item }}' regexp: '{{ item }}'
with_items: with_items:
- 'kubeasz' - 'kubeasz'
- 'helm' - 'helm completion'
- 'kubectl completion' - 'kubectl completion'
- 'crictl completion'
- 'HELM_TLS_ENABLE' - 'HELM_TLS_ENABLE'

View File

@ -65,6 +65,7 @@
- "/etc/systemd/system/kube-scheduler.service" - "/etc/systemd/system/kube-scheduler.service"
# 清理集群docker服务、网络相关 # 清理集群docker服务、网络相关
- block:
- name: 清理kube-router相关 - name: 清理kube-router相关
shell: "{{ bin_dir }}/docker run --privileged --net=host cloudnativelabs/kube-router --cleanup-config" shell: "{{ bin_dir }}/docker run --privileged --net=host cloudnativelabs/kube-router --cleanup-config"
ignore_errors: true ignore_errors: true
@ -101,6 +102,32 @@
- "/etc/bash_completion.d/docker" - "/etc/bash_completion.d/docker"
- "/usr/bin/docker" - "/usr/bin/docker"
when: "'kubeasz' not in install_info.stdout" when: "'kubeasz' not in install_info.stdout"
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'
- name: remove files and dirs2 - name: remove files and dirs2
file: name={{ item }} state=absent file: name={{ item }} state=absent
@ -123,7 +150,6 @@
&& iptables -F -t nat && iptables -X -t nat \ && iptables -F -t nat && iptables -X -t nat \
&& iptables -F -t raw && iptables -X -t raw \ && iptables -F -t raw && iptables -X -t raw \
&& iptables -F -t mangle && iptables -X -t mangle" && iptables -F -t mangle && iptables -X -t mangle"
when: "'kubeasz' not in install_info.stdout"
- name: cleanup networks1 - name: cleanup networks1
shell: "ip link del tunl0; \ shell: "ip link del tunl0; \
@ -142,7 +168,6 @@
systemctl restart networking; \ systemctl restart networking; \
systemctl restart network" systemctl restart network"
ignore_errors: true ignore_errors: true
when: "'kubeasz' not in install_info.stdout"
- name: cleanup 'calico' routes - name: cleanup 'calico' routes
shell: "for rt in `ip route|grep bird|sed 's/blackhole//'|awk '{print $1}'`;do ip route del $rt;done;" shell: "for rt in `ip route|grep bird|sed 's/blackhole//'|awk '{print $1}'`;do ip route del $rt;done;"
@ -208,8 +233,10 @@
regexp: '{{ item }}' regexp: '{{ item }}'
with_items: with_items:
- 'kubeasz' - 'kubeasz'
- 'helm' - 'helm completion'
- 'crictl completion'
- 'kubectl completion' - 'kubectl completion'
- 'HELM_TLS_ENABLE'
delegate_to: "{{ NODE_TO_DEL }}" delegate_to: "{{ NODE_TO_DEL }}"
run_once: true run_once: true