feat: add support to set nodename, part2

v3.4
gjmzj 2023-01-16 12:33:56 +08:00
parent a99635b7a0
commit 452bdec8f6
5 changed files with 31 additions and 20 deletions

View File

@ -26,6 +26,13 @@ CONTEXT_NAME: "context-{{ CLUSTER_NAME }}"
# k8s version
K8S_VER: "__k8s_ver__"
# set unique 'k8s_nodename' for each node, if not set(default:'') ip add will be used
K8S_NODENAME: "{%- if k8s_nodename != '' -%} \
{{ k8s_nodename }} \
{%- else -%} \
{{ inventory_hostname }} \
{%- endif -%}"
############################
# role:etcd
############################

View File

@ -64,9 +64,5 @@ cluster_dir="{{ base_dir }}/clusters/_cluster_name_"
# CA and other components cert/key Directory
ca_dir="/etc/kubernetes/ssl"
# set unique 'k8s_nodename' for each node, if not set(default:'') ip add will be used
K8S_NODENAME: "{%- if k8s_nodename != '' -%} \
{{ k8s_nodename }} \
{%- else -%} \
{{ inventory_hostname }} \
{%- endif -%}"
# Default 'k8s_nodename' is empty
k8s_nodename=''

View File

@ -68,9 +68,5 @@ cluster_dir="{{ base_dir }}/clusters/_cluster_name_"
# CA and other components cert/key Directory
ca_dir="/etc/kubernetes/ssl"
# set unique 'k8s_nodename' for each node, if not set(default:'') ip add will be used
K8S_NODENAME: "{%- if k8s_nodename != '' -%} \
{{ k8s_nodename }} \
{%- else -%} \
{{ inventory_hostname }} \
{%- endif -%}"
# Default 'k8s_nodename' is empty
k8s_nodename=''

View File

@ -20,8 +20,14 @@
- name: debug info
debug: var="DRAIN_OPT"
- name: run kubectl drain @{{ NODE_TO_DEL }}
shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_TO_DEL }} {{ DRAIN_OPT }}"
- name: get the node name to delete
shell: "{{ base_dir }}/bin/kubectl get node -owide|grep ' {{ NODE_TO_DEL }} '|awk '{print $1}'"
register: NODE_NAME
- debug: var="NODE_NAME.stdout"
- name: run kubectl drain @{{ NODE_NAME.stdout }}
shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_NAME.stdout }} {{ DRAIN_OPT }}"
#ignore_errors: true
- name: clean node {{ NODE_TO_DEL }}
@ -35,8 +41,8 @@
- debug: var="CLEAN_STATUS"
- name: run kubectl delete node {{ NODE_TO_DEL }}
shell: "{{ base_dir }}/bin/kubectl delete node {{ NODE_TO_DEL }}"
- name: run kubectl delete node {{ NODE_NAME.stdout }}
shell: "{{ base_dir }}/bin/kubectl delete node {{ NODE_NAME.stdout }}"
ignore_errors: true
# lineinfile is inadequate to delete lines between some specific line range

View File

@ -20,8 +20,14 @@
- name: debug info
debug: var="DRAIN_OPT"
- name: run kubectl drain @{{ NODE_TO_DEL }}
shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_TO_DEL }} {{ DRAIN_OPT }}"
- name: get the node name to delete
shell: "{{ base_dir }}/bin/kubectl get node -owide|grep ' {{ NODE_TO_DEL }} '|awk '{print $1}'"
register: NODE_NAME
- debug: var="NODE_NAME.stdout"
- name: run kubectl drain @{{ NODE_NAME.stdout }}
shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_NAME.stdout }} {{ DRAIN_OPT }}"
#ignore_errors: true
- name: clean node {{ NODE_TO_DEL }}
@ -36,8 +42,8 @@
- debug: var="CLEAN_STATUS"
- name: run kubectl delete node {{ NODE_TO_DEL }}
shell: "{{ base_dir }}/bin/kubectl delete node {{ NODE_TO_DEL }}"
- name: run kubectl delete node {{ NODE_NAME.stdout }}
shell: "{{ base_dir }}/bin/kubectl delete node {{ NODE_NAME.stdout }}"
ignore_errors: true
# lineinfile is inadequate to delete lines between some specific line range