2018-03-05 15:02:47 +08:00
|
|
|
---
|
2021-03-26 11:48:43 -04:00
|
|
|
- name: remove-node | List nodes
|
2021-04-09 03:24:02 +08:00
|
|
|
command: >-
|
|
|
|
{{ bin_dir }}/kubectl get nodes -o go-template={% raw %}'{{ range .items }}{{ .metadata.name }}{{ "\n" }}{{ end }}'{% endraw %}
|
2021-01-15 15:17:43 -06:00
|
|
|
register: nodes
|
2021-03-23 17:26:05 -07:00
|
|
|
delegate_to: "{{ groups['kube_control_plane']|first }}"
|
2021-01-15 15:17:43 -06:00
|
|
|
changed_when: false
|
|
|
|
run_once: true
|
|
|
|
|
2020-07-27 15:24:17 +02:00
|
|
|
- name: remove-node | Drain node except daemonsets resource # noqa 301
|
2018-03-05 15:02:47 +08:00
|
|
|
command: >-
|
2021-09-23 10:19:13 -07:00
|
|
|
{{ bin_dir }}/kubectl --kubeconfig {{ kube_config_dir }}/admin.conf drain
|
2018-03-05 15:02:47 +08:00
|
|
|
--force
|
|
|
|
--ignore-daemonsets
|
|
|
|
--grace-period {{ drain_grace_period }}
|
|
|
|
--timeout {{ drain_timeout }}
|
2021-10-14 11:25:19 +02:00
|
|
|
--delete-emptydir-data {{ hostvars[item]['kube_override_hostname']|default(item) }}
|
2021-04-29 15:20:50 +03:00
|
|
|
loop: "{{ node.split(',') | default(groups['kube_node']) }}"
|
2021-03-26 11:48:43 -04:00
|
|
|
# ignore servers that are not nodes
|
|
|
|
when: hostvars[item]['kube_override_hostname']|default(item) in nodes.stdout_lines
|
2020-10-29 02:55:56 +07:00
|
|
|
register: result
|
2020-12-31 00:15:49 +09:00
|
|
|
failed_when: result.rc != 0 and not allow_ungraceful_removal
|
2021-03-23 17:26:05 -07:00
|
|
|
delegate_to: "{{ groups['kube_control_plane']|first }}"
|
2018-06-23 06:40:59 +00:00
|
|
|
run_once: true
|
2021-01-15 15:17:43 -06:00
|
|
|
until: result.rc == 0 or allow_ungraceful_removal
|
|
|
|
retries: "{{ drain_retries }}"
|
|
|
|
delay: "{{ drain_retry_delay_seconds }}"
|