diff options
author | Christian Pointner <equinox@spreadspace.org> | 2022-08-16 23:37:21 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2022-08-16 23:37:27 +0200 |
commit | b2a99f806fba7f7c8083670308721b291d7c34e9 (patch) | |
tree | db6b071948a679fa4f6926cb5c421c2bc8c4cb43 /roles/kubernetes/kubeadm | |
parent | kubernetes/kubeadm: make k8s node name configureable (diff) |
kubernetes/kubeadm: fix node pruning by adding a node label for ansible inventroy hostname
Diffstat (limited to 'roles/kubernetes/kubeadm')
4 files changed, 15 insertions, 6 deletions
diff --git a/roles/kubernetes/kubeadm/control-plane/templates/kubeadm-init.config.j2 b/roles/kubernetes/kubeadm/control-plane/templates/kubeadm-init.config.j2 index 23cd36e6..e08ea66d 100644 --- a/roles/kubernetes/kubeadm/control-plane/templates/kubeadm-init.config.j2 +++ b/roles/kubernetes/kubeadm/control-plane/templates/kubeadm-init.config.j2 @@ -18,8 +18,9 @@ skipPhases: nodeRegistration: name: "{{ kubernetes_node_name }}" criSocket: "{{ kubernetes_cri_socket }}" -{% if kubernetes_overlay_node_ip is defined %} kubeletExtraArgs: + node-labels: "ansible.spreadsapce.org/inventory_hostname={{ inventory_hostname }}" +{% if kubernetes_overlay_node_ip is defined %} node-ip: "{{ kubernetes_overlay_node_ip }}" {% endif %} --- diff --git a/roles/kubernetes/kubeadm/control-plane/templates/kubeadm-join.config.j2 b/roles/kubernetes/kubeadm/control-plane/templates/kubeadm-join.config.j2 index 77da9021..9f79fbad 100644 --- a/roles/kubernetes/kubeadm/control-plane/templates/kubeadm-join.config.j2 +++ b/roles/kubernetes/kubeadm/control-plane/templates/kubeadm-join.config.j2 @@ -18,7 +18,8 @@ controlPlane: nodeRegistration: name: "{{ kubernetes_node_name }}" criSocket: "{{ kubernetes_cri_socket }}" -{% if kubernetes_overlay_node_ip is defined %} kubeletExtraArgs: + node-labels: "ansible.spreadsapce.org/inventory_hostname={{ inventory_hostname }}" +{% if kubernetes_overlay_node_ip is defined %} node-ip: "{{ kubernetes_overlay_node_ip }}" {% endif %} diff --git a/roles/kubernetes/kubeadm/prune/tasks/main.yml b/roles/kubernetes/kubeadm/prune/tasks/main.yml index 1c746294..88ab7ecd 100644 --- a/roles/kubernetes/kubeadm/prune/tasks/main.yml +++ b/roles/kubernetes/kubeadm/prune/tasks/main.yml @@ -1,9 +1,15 @@ --- -- name: remove nodes from api server +- name: drain and remove superflous nodes run_once: true delegate_to: "{{ groups['_kubernetes_primary_controlplane_node_'] | first }}" - loop: "{{ groups['_kubernetes_nodes_prune_'] | default([]) }}" - command: "kubectl delete node {{ hostvars[item].kubernetes_node_name }}" + block: + - name: drain superflous nodes + loop: "{{ groups['_kubernetes_nodes_prune_'] | default([]) }}" + command: "kubectl --kubeconfig /etc/kubernetes/admin.conf drain {{ hostvars[item].kubernetes_node_name }} --delete-local-data --force --ignore-daemonsets" + + - name: remove nodes from api server + loop: "{{ groups['_kubernetes_nodes_prune_'] | default([]) }}" + command: "kubectl --kubeconfig /etc/kubernetes/admin.conf delete node {{ hostvars[item].kubernetes_node_name }}" - name: prune network plugin include_tasks: "net_{{ kubernetes_network_plugin }}.yml" diff --git a/roles/kubernetes/kubeadm/worker/templates/kubeadm.config.j2 b/roles/kubernetes/kubeadm/worker/templates/kubeadm.config.j2 index 70314fde..302e3e76 100644 --- a/roles/kubernetes/kubeadm/worker/templates/kubeadm.config.j2 +++ b/roles/kubernetes/kubeadm/worker/templates/kubeadm.config.j2 @@ -11,7 +11,8 @@ discovery: nodeRegistration: name: "{{ kubernetes_node_name }}" criSocket: "{{ kubernetes_cri_socket }}" -{% if kubernetes_overlay_node_ip is defined %} kubeletExtraArgs: + node-labels: "ansible.spreadsapce.org/inventory_hostname={{ inventory_hostname }}" +{% if kubernetes_overlay_node_ip is defined %} node-ip: "{{ kubernetes_overlay_node_ip }}" {% endif %} |