From 1debc443b12931defb29c690066ca413105cc29b Mon Sep 17 00:00:00 2001 From: Felix Seifert Date: Fri, 12 Sep 2025 21:48:19 +0200 Subject: [PATCH] feat: allow staggered reboot of K3s cluster nodes --- README.md | 10 ++++++++++ reboot.yml | 22 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 37ba59b..dd0adf7 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,16 @@ ansible-playbook reset.yml -i inventory/my-cluster/hosts.ini >You should also reboot these nodes due to the VIP not being destroyed +### ⏻️ Reboot Cluster Nodes + +The cluster nodes can all be rebooted at once, or staggered. For a staggered reboot, you can use `concurrent_reboots` to specify +how many nodes can be rebooted simultaneously. You can also use `wait_seconds_after_reboot` to specify how many seconds wait +time there should be between a successful reboot and starting the next reboot; this could be helpful for waiting to restart pods. + +```bash +ansible-playbook reboot.yml -i inventory/my-cluster/hosts.ini --extra-vars 'concurrent_reboots=2 wait_seconds_after_reboot=30' +``` + ## ⚙️ Kube Config To copy your `kube config` locally so that you can access your **Kubernetes** cluster run: diff --git a/reboot.yml b/reboot.yml index e0fa8b9..fa98b06 100644 --- a/reboot.yml +++ b/reboot.yml @@ -2,9 +2,27 @@ - name: Reboot k3s_cluster hosts: k3s_cluster gather_facts: true + + # concurrent_reboots defines how many hosts to reboot concurrently, if not defined, all hosts rebooted at once + serial: "{{ concurrent_reboots | default('100%') }}" + tasks: - - name: Reboot the nodes (and Wait upto 5 mins max) - become: true + - name: >- + {{ + 'Reboot all nodes at once' + if (concurrent_reboots is not defined) + else 'Reboot nodes with concurrency of ' ~ concurrent_reboots + }} ansible.builtin.reboot: reboot_command: "{{ custom_reboot_command | default(omit) }}" reboot_timeout: 300 + test_command: >- + {{ 'kubectl get nodes' if 'master' in group_names else 'whoami' }} + + - name: Optional wait after reboot before next rebooting next node + ansible.builtin.pause: + seconds: "{{ wait_seconds_after_reboot | default(0) }}" + when: >- + concurrent_reboots is defined and + wait_seconds_after_reboot is defined and + wait_seconds_after_reboot | int > 0