Co-authored-by: Devin Buhl <onedr0p@users.noreply.github.com>
85 lines
3.1 KiB
YAML
85 lines
3.1 KiB
YAML
---
|
|
# https://github.com/kevincoakley/ansible-role-k8s-rolling-update
|
|
- name: Cluster rollout update
|
|
hosts: all
|
|
become: true
|
|
gather_facts: true
|
|
any_errors_fatal: true
|
|
serial: 1
|
|
pre_tasks:
|
|
- name: Pausing for 5 seconds...
|
|
ansible.builtin.pause:
|
|
seconds: 5
|
|
tasks:
|
|
- name: Details
|
|
ansible.builtin.command: "kubectl get node {% raw %}{{ inventory_hostname }}{% endraw %} -o json"
|
|
register: kubectl_get_node
|
|
delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}"
|
|
failed_when: false
|
|
changed_when: false
|
|
|
|
- name: Update
|
|
when:
|
|
# When status.conditions[x].type == Ready then check stats.conditions[x].status for True|False
|
|
- kubectl_get_node['stdout'] | from_json | json_query("status.conditions[?type == 'Ready'].status")
|
|
# If spec.unschedulable is defined then the node is cordoned
|
|
- not (kubectl_get_node['stdout'] | from_json).spec.unschedulable is defined
|
|
block:
|
|
- name: Cordon
|
|
kubernetes.core.k8s_drain:
|
|
name: "{% raw %}{{ inventory_hostname }}{% endraw %}"
|
|
kubeconfig: /etc/rancher/k3s/k3s.yaml
|
|
state: cordon
|
|
delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}"
|
|
|
|
- name: Drain
|
|
ansible.builtin.command: "kubectl drain --pod-selector='app!=rook-ceph-osd,app!=csi-attacher,app!=csi-provisioner' --ignore-daemonsets --delete-emptydir-data --force --grace-period=300 {% raw %}{{ inventory_hostname }}{% endraw %}"
|
|
delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}"
|
|
changed_when: false
|
|
|
|
### pod_selectors feature in upcoming kubernetes.core 2.5.0 ###
|
|
# - name: Drain
|
|
# kubernetes.core.k8s_drain:
|
|
# name: "{% raw %}{{ inventory_hostname }}{% endraw %}"
|
|
# kubeconfig: /etc/rancher/k3s/k3s.yaml
|
|
# state: drain
|
|
# delete_options:
|
|
# delete_emptydir_data: true
|
|
# ignore_daemonsets: true
|
|
# terminate_grace_period: 600
|
|
# wait_timeout: 900
|
|
# force: true
|
|
# pod_selectors:
|
|
# # Rook Ceph
|
|
# - app!=rook-ceph-osd
|
|
# # Longhorn
|
|
# - app!=csi-attacher
|
|
# # Longhorn
|
|
# - app!=csi-provisioner
|
|
# delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}"
|
|
|
|
- name: Update
|
|
ansible.builtin.apt:
|
|
upgrade: dist
|
|
update_cache: true
|
|
|
|
- name: Check if reboot is required
|
|
ansible.builtin.stat:
|
|
path: /var/run/reboot-required
|
|
register: reboot_required
|
|
|
|
- name: Reboot
|
|
when: reboot_required.stat.exists
|
|
ansible.builtin.reboot:
|
|
msg: Rebooting node
|
|
post_reboot_delay: 60
|
|
reboot_timeout: 3600
|
|
when: reboot_required.stat.exists
|
|
|
|
- name: Uncordon
|
|
kubernetes.core.k8s_drain:
|
|
name: "{% raw %}{{ inventory_hostname }}{% endraw %}"
|
|
kubeconfig: /etc/rancher/k3s/k3s.yaml
|
|
state: uncordon
|
|
delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}"
|