mirror of https://github.com/easzlab/kubeasz.git
easzctl增加del-master/del-node功能
parent
48697d9f34
commit
17534ed8ec
|
@ -1,4 +1,6 @@
|
|||
# remove a etcd member
|
||||
# 警告:此脚本将清理指定 etcd 节点
|
||||
# 使用:`easzctl del-etcd 1.1.1.1`
|
||||
|
||||
- hosts: localhost
|
||||
vars_prompt:
|
||||
- name: "ETCD_TO_DEL"
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
# 警告:此脚本将清理指定 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 etcd cluster!"
|
||||
when: "groups['etcd']|length < 2 and NODE_TO_DEL in groups['etcd']"
|
||||
|
||||
- name: fail info2
|
||||
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"
|
||||
roles:
|
||||
- clean
|
||||
task:
|
||||
- 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
|
|
@ -0,0 +1,37 @@
|
|||
# 警告:此脚本将清理指定 kube-master 节点
|
||||
# 使用:`easzctl del-master 1.1.1.1`
|
||||
|
||||
- hosts: "{{ NODE_TO_DEL }}"
|
||||
tasks:
|
||||
- name: fail info1
|
||||
fail: msg="you CAN NOT delete the last member of etcd cluster!"
|
||||
when: "groups['etcd']|length < 2 and NODE_TO_DEL in groups['etcd']"
|
||||
|
||||
- name: fail info2
|
||||
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_MASTER: "yes"
|
||||
DEL_NODE: "yes"
|
||||
DEL_LB: "yes"
|
||||
roles:
|
||||
- clean
|
||||
task:
|
||||
- name: 执行 kubectl delete node
|
||||
shell: "{{ bin_dir }}/kubectl delete node {{ NODE_TO_DEL }}"
|
||||
delegate_to: "{{ groups['kube-node'][0] }}"
|
||||
|
||||
# 删除 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
|
|
@ -23,6 +23,8 @@ In-cluster operation:
|
|||
add-node To add a kube-node(work node) to the k8s cluster
|
||||
clean-node To clean a node, whatever role the node plays
|
||||
del-etcd To delete a etcd-node from the etcd cluster
|
||||
del-master To delete a kube-master from the k8s cluster
|
||||
del-node To delete a kube-node from the k8s cluster
|
||||
upgrade To upgrade the k8s cluster
|
||||
|
||||
Extra operation:
|
||||
|
@ -46,6 +48,12 @@ function help-info() {
|
|||
(del-etcd)
|
||||
echo -e "Usage: easzctl del-etcd <etcd_ip>\n\nread 'https://github.com/easzlab/kubeasz/blob/master/docs/op/op-etcd.md'"
|
||||
;;
|
||||
(del-master)
|
||||
echo -e "Usage: easzctl del-master <master_ip>\n\nread 'https://github.com/easzlab/kubeasz/blob/master/docs/op/op-master.md'"
|
||||
;;
|
||||
(del-node)
|
||||
echo -e "Usage: easzctl del-node <node_ip>\n\nread 'https://github.com/easzlab/kubeasz/blob/master/docs/op/op-node.md'"
|
||||
;;
|
||||
(clean-node)
|
||||
echo -e "Usage: easzctl clean-node <node_ip>\n\nread 'https://github.com/easzlab/kubeasz/blob/master/docs/op/clean_one_node.md'"
|
||||
;;
|
||||
|
@ -147,6 +155,39 @@ function del-etcd() {
|
|||
return 0
|
||||
}
|
||||
|
||||
function del-node() {
|
||||
# check node's address regexp
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "[ERROR] Invalid ip address!"; return 2; }
|
||||
|
||||
#
|
||||
ansible-playbook $BASEPATH/tools/12.delnode.yml -e ETCD_TO_DEL=$1 || { echo "[ERROR] Failed to delete 'kube-node': $1!"; return 2; }
|
||||
|
||||
# remove node in ansible hosts
|
||||
sed -i '/^\[kube-node/,/^\[harbor/{/^'"$1"'[^0-9]*$/d}' $BASEPATH/hosts
|
||||
|
||||
# save current cluster context if needed
|
||||
[ -f "$BASEPATH/.cluster/current_cluster" ] && save_context
|
||||
return 0
|
||||
}
|
||||
|
||||
function del-master() {
|
||||
# check node's address regexp
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "[ERROR] Invalid ip address!"; return 2; }
|
||||
|
||||
#
|
||||
ansible-playbook $BASEPATH/tools/13.delmaster.yml -e ETCD_TO_DEL=$1 || { echo "[ERROR] Failed to delete 'kube-master': $1!"; return 2; }
|
||||
|
||||
# remove node in ansible hosts
|
||||
sed -i '/^\[kube-master/,/^\[kube-node/{/^'"$1"'[^0-9]*$/d}' $BASEPATH/hosts
|
||||
|
||||
# reconfig kubeconfig in ansible controller
|
||||
ansible-playbook $BASEPATH/01.prepare.yml -t create_kctl_cfg
|
||||
|
||||
# save current cluster context if needed
|
||||
[ -f "$BASEPATH/.cluster/current_cluster" ] && save_context
|
||||
return 0
|
||||
}
|
||||
|
||||
function clean-node() {
|
||||
# check node's address regexp
|
||||
[[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "[ERROR] Invalid ip address!"; return 2; }
|
||||
|
@ -367,30 +408,40 @@ BASEPATH=/etc/ansible
|
|||
|
||||
case "$1" in
|
||||
### in-cluster operations #####################
|
||||
(add-node)
|
||||
(add-etcd)
|
||||
[ "$#" -gt 1 ] || { usage >&2; exit 2; }
|
||||
ACTION="Action: add a k8s work node"
|
||||
CMD="add-node $2"
|
||||
ACTION="Action: add a etcd node"
|
||||
CMD="add-etcd $2"
|
||||
;;
|
||||
(add-master)
|
||||
[ "$#" -gt 1 ] || { usage >&2; exit 2; }
|
||||
ACTION="Action: add a k8s master node"
|
||||
CMD="add-master $2"
|
||||
;;
|
||||
(add-etcd)
|
||||
(add-node)
|
||||
[ "$#" -gt 1 ] || { usage >&2; exit 2; }
|
||||
ACTION="Action: add a etcd node"
|
||||
CMD="add-etcd $2"
|
||||
ACTION="Action: add a k8s work node"
|
||||
CMD="add-node $2"
|
||||
;;
|
||||
(clean-node)
|
||||
[ "$#" -gt 1 ] || { usage >&2; exit 2; }
|
||||
ACTION="Action: clean a node"
|
||||
CMD="clean-node $2"
|
||||
;;
|
||||
(del-etcd)
|
||||
[ "$#" -gt 1 ] || { usage >&2; exit 2; }
|
||||
ACTION="Action: delete a etcd node"
|
||||
CMD="del-etcd $2"
|
||||
;;
|
||||
(clean-node)
|
||||
(del-master)
|
||||
[ "$#" -gt 1 ] || { usage >&2; exit 2; }
|
||||
ACTION="Action: clean a node"
|
||||
CMD="clean-node $2"
|
||||
ACTION="Action: delete a kube-master"
|
||||
CMD="del-master $2"
|
||||
;;
|
||||
(del-node)
|
||||
[ "$#" -gt 1 ] || { usage >&2; exit 2; }
|
||||
ACTION="Action: delete a kube-node"
|
||||
CMD="del-node $2"
|
||||
;;
|
||||
(upgrade)
|
||||
ACTION="Action: upgrade the cluster"
|
||||
|
|
Loading…
Reference in New Issue