Last active
November 21, 2022 15:57
-
-
Save codatory/44e4944a1363e9ffadb9db2d0919b672 to your computer and use it in GitHub Desktop.
Kubernetes host patching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
children: | |
control: | |
hosts: | |
10.8.0.11: | |
node_name: k-c-1 | |
10.8.0.12: | |
node_name: k-c-2 | |
10.8.0.13: | |
node_name: k-c-3 | |
work: | |
hosts: | |
10.8.0.21: | |
node_name: k-w-a | |
10.8.0.22: | |
node_name: k-w-b | |
10.8.0.23: | |
node_name: k-w-c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Kubernetes Cluster Patching | |
hosts: all | |
gather_facts: no | |
become: true | |
order: shuffle | |
serial: 1 | |
tasks: | |
- name: Install needrestart | |
apt: | |
cache_valid_time: 900 | |
name: needrestart | |
- name: Update Apt Packages | |
apt: | |
upgrade: yes | |
autoremove: yes | |
autoclean: yes | |
- name: Check if reboot is required | |
stat: | |
path: /var/run/reboot-required | |
register: reboot_required | |
- name: Check if service restart is required | |
command: 'needrestart -p' | |
register: needrestart | |
ignore_errors: true | |
- name: Drain, Reboot and Uncordon Node | |
when: reboot_required.stat.exists or needrestart.failed | |
block: | |
- name: Drain system | |
connection: local | |
become: false | |
command: "kubectl drain {{ node_name }} --force=true --grace-period=120 --timeout=300s --ignore-daemonsets --delete-emptydir-data" | |
- name: Restart System | |
reboot: | |
post_reboot_delay: 5 | |
pre_reboot_delay: 90 | |
- name: Waiting for host to stabilize | |
pause: | |
minutes: 5 | |
always: | |
- name: Uncordon System | |
connection: local | |
become: false | |
command: "kubectl uncordon {{ node_name }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment