Abstract
This role resets the control planes in your inventory with Kubeadm.
Reset Cluster#
Reset Role Usage#
This role should generally be executed first to attempt to create a fresh environment.
---
###
# ```{rubric} Reset an existing cluster
# ```
# ---
# This playbook runs `kubeadm reset -f`{l=shell} on a control plane node.
#
# ```{literalinclude} /roles/reset/tasks/main.yml
# :language: yaml
# :start-at: "- name: Reset existing cluster\n"
# :end-at: " register: reset_out\n"
# ```
- name: Ensure required programs
community.general.pacman:
executable: yay
extra_args: '--noconfirm'
name: "{{ item }}"
state: present
loop:
- kubeadm
- kubelet
- kubectl
- kubie
- name: Make sure the kube group exists
ansible.builtin.group:
name: kube
state: present
- name: Add required users to group
ansible.builtin.user:
name: "{{ item }}"
groups: kube
append: true
loop:
- root
- "{{ nonroot_user }}"
- name: Reset existing cluster
ansible.builtin.command:
cmd: kubeadm reset -f &> /root/reset.md
removes: /etc/kubernetes/admin.conf
register: reset_out
- name: Clear CNI config
ansible.builtin.file:
dest: /etc/cni/net.d
state: absent
- name: Re-add CNI config directory
ansible.builtin.file:
dest: /etc/cni/net.d
state: directory
owner: root
group: root
mode: u+rwx,go-rwx
###
# ```{rubric} Show and record output
# ```
# ---
# These tasks display the output from the command above, then write them to
# disk in a temporary location.
#
# ```{literalinclude} /roles/reset/tasks/main.yml
# :language: yaml
# :start-at: "- name: Show output\n"
# ```
- name: Show output
ansible.builtin.debug:
var: reset_out
- name: Drop reset output
ansible.builtin.file:
dest: /root/reset.md
state: absent
- name: Stop containerd
ansible.builtin.service:
state: stopped
name: containerd
- name: Stop kubelet
ansible.builtin.service:
state: stopped
name: kubelet
- name: Start containerd
ansible.builtin.service:
state: started
name: containerd
- name: Start kubelet
ansible.builtin.service:
state: started
name: kubelet