更新清理脚本支持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'的容器
shell: 'docker ps|grep kubeasz || echo "NOT FOUND"'
register: install_info
- name: stop and disable docker service
service:
name: docker
state: stopped
enabled: no
ignore_errors: true
when: "'kubeasz' not in install_info.stdout"
# 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
when: "'kubeasz' not in install_info.stdout"
- name: unmount docker filesystem-2
mount: path=/var/lib/docker/overlay state=unmounted
when: "'kubeasz' not in install_info.stdout"
- 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: "'kubeasz' not in install_info.stdout"
when: CONTAINER_RUNTIME == 'docker'
- name: 获取是否运行名为'kubeasz'的容器 - block:
shell: 'docker ps|grep kubeasz || echo "NOT FOUND"' - name: stop and disable containerd service
register: install_info service:
name: containerd
state: stopped
enabled: no
ignore_errors: true
- name: stop and disable docker service - name: umount containerd filesystems
service: shell: "mount | grep 'containerd/io.containerd'| awk '{print $3}'|xargs umount || exit 0"
name: docker args:
state: stopped warn: false
enabled: no ignore_errors: true
ignore_errors: true
when: "'kubeasz' not in install_info.stdout"
# as k8s-network-plugins use host-network, '/var/run/docker/netns/default' must be umounted - name: remove files and dirs
- name: unmount docker filesystem-1 file: name={{ item }} state=absent
mount: path=/var/run/docker/netns/default state=unmounted with_items:
when: "'kubeasz' not in install_info.stdout" - "/etc/containerd/"
- "/etc/crictl.yaml"
- name: unmount docker filesystem-2 - "/etc/systemd/system/containerd.service"
mount: path=/var/lib/docker/overlay state=unmounted - "/opt/containerd/"
when: "'kubeasz' not in install_info.stdout" - "/var/lib/containerd/"
- "/var/run/containerd/"
- name: remove files and dirs when: CONTAINER_RUNTIME == 'containerd'
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: "'kubeasz' not in install_info.stdout"
- 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,43 +65,70 @@
- "/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'的容器
shell: 'docker ps|grep kubeasz || echo "NOT FOUND"' - name: 获取是否运行名为'kubeasz'的容器
register: install_info shell: 'docker ps|grep kubeasz || echo "NOT FOUND"'
register: install_info
- name: stop and disable docker service
service: - name: stop and disable docker service
name: docker service:
state: stopped name: docker
enabled: no state: stopped
ignore_errors: true enabled: no
when: "'kubeasz' not in install_info.stdout" ignore_errors: true
when: "'kubeasz' not in install_info.stdout"
- name: unmount docker filesystem-1
mount: path=/var/run/docker/netns/default state=unmounted - name: unmount docker filesystem-1
when: "'kubeasz' not in install_info.stdout" mount: path=/var/run/docker/netns/default state=unmounted
when: "'kubeasz' not in install_info.stdout"
- name: unmount docker filesystem-2
mount: path=/var/lib/docker/overlay state=unmounted - name: unmount docker filesystem-2
when: "'kubeasz' not in install_info.stdout" mount: path=/var/lib/docker/overlay state=unmounted
when: "'kubeasz' not in install_info.stdout"
- name: remove files and dirs
file: name={{ item }} state=absent - name: remove files and dirs
with_items: file: name={{ item }} state=absent
- "/var/lib/docker/" with_items:
- "/var/run/docker/" - "/var/lib/docker/"
- "/etc/systemd/system/docker.service" - "/var/run/docker/"
- "/etc/systemd/system/docker.service.requires/" - "/etc/systemd/system/docker.service"
- "/etc/systemd/system/docker.service.d/" - "/etc/systemd/system/docker.service.requires/"
- "/etc/bash_completion.d/docker" - "/etc/systemd/system/docker.service.d/"
- "/usr/bin/docker" - "/etc/bash_completion.d/docker"
when: "'kubeasz' not in install_info.stdout" - "/usr/bin/docker"
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
with_items: with_items:
@ -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