diff --git a/remove-node.yml b/remove-node.yml new file mode 100644 index 000000000..fbc5bc8ba --- /dev/null +++ b/remove-node.yml @@ -0,0 +1,29 @@ +--- + +- hosts: all + gather_facts: true + +- hosts: etcd:k8s-cluster:vault:calico-rr + vars_prompt: + name: "delete_nodes_confirmation" + prompt: "Are you sure you want to delete nodes state? Type 'yes' to delete nodes." + default: "no" + private: no + + pre_tasks: + - name: check confirmation + fail: + msg: "Delete nodes confirmation failed" + when: delete_nodes_confirmation != "yes" + +- hosts: kube-master + roles: + - { role: remove-node/pre-remove, tags: pre-remove } + +- hosts: kube-node + roles: + - { role: reset, tags: reset } + +- hosts: kube-master + roles: + - { role: remove-node/post-remove, tags: post-remove } diff --git a/roles/remove-node/post-remove/tasks/main.yml b/roles/remove-node/post-remove/tasks/main.yml new file mode 100644 index 000000000..395f9986b --- /dev/null +++ b/roles/remove-node/post-remove/tasks/main.yml @@ -0,0 +1,8 @@ +--- + +- name: Delete node + command: kubectl delete node {{ item }} + with_items: + - "{{ groups['kube-node'] }}" + delegate_to: "{{ groups['kube-master'][0] }}" + ignore_errors: yes diff --git a/roles/remove-node/pre-remove/defaults/main.yml b/roles/remove-node/pre-remove/defaults/main.yml new file mode 100644 index 000000000..e9e1ba28d --- /dev/null +++ b/roles/remove-node/pre-remove/defaults/main.yml @@ -0,0 +1,3 @@ +--- +drain_grace_period: 300 +drain_timeout: 360s diff --git a/roles/remove-node/pre-remove/tasks/main.yml b/roles/remove-node/pre-remove/tasks/main.yml new file mode 100644 index 000000000..12091917a --- /dev/null +++ b/roles/remove-node/pre-remove/tasks/main.yml @@ -0,0 +1,15 @@ +--- + +- name: remove-node | Drain node except daemonsets resource + command: >- + {{ bin_dir }}/kubectl drain + --force + --ignore-daemonsets + --grace-period {{ drain_grace_period }} + --timeout {{ drain_timeout }} + --delete-local-data {{ item }} + with_items: + - "{{ groups['kube-node'] }}" + failed_when: false + delegate_to: "{{ groups['kube-master'][0] }}" + ignore_errors: yes