更新清理脚本支持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,48 +48,75 @@
- "/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:
- name: clean 'kube-router' stuff - block:
shell: "{{ bin_dir }}/docker run --privileged --net=host cloudnativelabs/kube-router --cleanup-config" - name: clean 'kube-router' stuff
ignore_errors: true shell: "{{ bin_dir }}/docker run --privileged --net=host cloudnativelabs/kube-router --cleanup-config"
when: "CLUSTER_NETWORK == 'kube-router'" ignore_errors: true
when: "CLUSTER_NETWORK == 'kube-router'"
- name: 获取是否运行名为'kubeasz'的容器 - name: 获取是否运行名为'kubeasz'的容器
shell: 'docker ps|grep kubeasz || echo "NOT FOUND"' shell: 'docker ps|grep kubeasz || echo "NOT FOUND"'
register: install_info register: install_info
- name: stop and disable docker service - name: stop and disable docker service
service: service:
name: docker name: docker
state: stopped state: stopped
enabled: no enabled: no
ignore_errors: true ignore_errors: true
when: "'kubeasz' not in install_info.stdout" when: "'kubeasz' not in install_info.stdout"
# as k8s-network-plugins use host-network, '/var/run/docker/netns/default' must be umounted # as k8s-network-plugins use host-network, '/var/run/docker/netns/default' must be umounted
- name: unmount docker filesystem-1 - name: unmount docker filesystem-1
mount: path=/var/run/docker/netns/default state=unmounted mount: path=/var/run/docker/netns/default state=unmounted
when: "'kubeasz' not in install_info.stdout" when: "'kubeasz' not in install_info.stdout"
- name: unmount docker filesystem-2 - name: unmount docker filesystem-2
mount: path=/var/lib/docker/overlay state=unmounted mount: path=/var/lib/docker/overlay state=unmounted
when: "'kubeasz' not in install_info.stdout" when: "'kubeasz' not in install_info.stdout"
- name: remove files and dirs - name: remove files and dirs
file: name={{ item }} state=absent file: name={{ item }} state=absent
with_items: with_items:
- "/var/lib/docker/" - "/var/lib/docker/"
- "/var/run/docker/" - "/var/run/docker/"
- "/etc/systemd/system/docker.service" - "/etc/systemd/system/docker.service"
- "/etc/systemd/system/docker.service.requires/" - "/etc/systemd/system/docker.service.requires/"
- "/etc/systemd/system/docker.service.d/" - "/etc/systemd/system/docker.service.d/"
- "/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,42 +65,69 @@
- "/etc/systemd/system/kube-scheduler.service" - "/etc/systemd/system/kube-scheduler.service"
# 清理集群docker服务、网络相关 # 清理集群docker服务、网络相关
- name: 清理kube-router相关 - block:
shell: "{{ bin_dir }}/docker run --privileged --net=host cloudnativelabs/kube-router --cleanup-config" - name: 清理kube-router相关
ignore_errors: true shell: "{{ bin_dir }}/docker run --privileged --net=host cloudnativelabs/kube-router --cleanup-config"
when: "CLUSTER_NETWORK == 'kube-router'" ignore_errors: true
when: "CLUSTER_NETWORK == 'kube-router'"
- name: 获取是否运行名为'kubeasz'的容器 - name: 获取是否运行名为'kubeasz'的容器
shell: 'docker ps|grep kubeasz || echo "NOT FOUND"' shell: 'docker ps|grep kubeasz || echo "NOT FOUND"'
register: install_info register: install_info
- name: stop and disable docker service - name: stop and disable docker service
service: service:
name: docker name: docker
state: stopped state: stopped
enabled: no enabled: no
ignore_errors: true ignore_errors: true
when: "'kubeasz' not in install_info.stdout" when: "'kubeasz' not in install_info.stdout"
- name: unmount docker filesystem-1 - name: unmount docker filesystem-1
mount: path=/var/run/docker/netns/default state=unmounted mount: path=/var/run/docker/netns/default state=unmounted
when: "'kubeasz' not in install_info.stdout" when: "'kubeasz' not in install_info.stdout"
- name: unmount docker filesystem-2 - name: unmount docker filesystem-2
mount: path=/var/lib/docker/overlay state=unmounted mount: path=/var/lib/docker/overlay state=unmounted
when: "'kubeasz' not in install_info.stdout" when: "'kubeasz' not in install_info.stdout"
- name: remove files and dirs - name: remove files and dirs
file: name={{ item }} state=absent file: name={{ item }} state=absent
with_items: with_items:
- "/var/lib/docker/" - "/var/lib/docker/"
- "/var/run/docker/" - "/var/run/docker/"
- "/etc/systemd/system/docker.service" - "/etc/systemd/system/docker.service"
- "/etc/systemd/system/docker.service.requires/" - "/etc/systemd/system/docker.service.requires/"
- "/etc/systemd/system/docker.service.d/" - "/etc/systemd/system/docker.service.d/"
- "/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