kubeasz/tools/12.delnode.yml

35 lines
1012 B
YAML

# 警告:此脚本将清理指定 kube-node 节点
# 使用:`easzctl del-node 1.1.1.1`
- hosts: "{{ NODE_TO_DEL }}"
tasks:
- name: fail info1
fail: msg="you CAN NOT delete the last member of kube-master!"
when: "groups['kube-master']|length < 2 and NODE_TO_DEL in groups['kube-master']"
- name: 执行 kubectl drain 迁移 pod
shell: "{{ bin_dir }}/kubectl drain {{ NODE_TO_DEL }} --ignore-daemonsets --delete-local-data"
connection: local
ignore_errors: true
- hosts: "{{ NODE_TO_DEL }}"
vars:
DEL_NODE: "yes"
DEL_LB: "yes"
DEL_CHRONY: "yes"
DEL_ENV: "yes"
roles:
- clean
tasks:
- name: 执行 kubectl delete node
shell: "{{ bin_dir }}/kubectl delete node {{ NODE_TO_DEL }}"
connection: local
# 删除 ansible hosts 中节点配置
# - name: rm {{ NODE_TO_DEL }} in ansible hosts
# lineinfile:
# dest: "{{ base_dir }}/hosts"
# state: absent
# regexp: '^{{ NODE_TO_DEL }}$|^{{ NODE_TO_DEL }}[^0-9]'
# connection: local