-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkubernetes_update_nodes.yml
116 lines (102 loc) · 2.84 KB
/
kubernetes_update_nodes.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
- name: system updates
hosts: k8s-worker
become: true
serial: 5
tasks:
- name: print host
become: false
debug:
var: inventory_hostname
- name: drain hosts
become: false
environment:
KUBECONFIG: "{{ lookup('env', 'KUBECONFIG') }}"
kubernetes.core.k8s_drain:
name: "{{ inventory_hostname }}"
delete_options:
delete_emptydir_data: true
ignore_daemonsets: true
terminate_grace_period: 0
delegate_to: 127.0.0.1
ignore_errors: true
- name: update packages
ansible.builtin.shell: yum update -y --disablerepo=kubernetes
when: ansible_os_family == "RedHat"
- name: update debian/ubuntu packages
ansible.builtin.apt:
update_cache: yes
cache_valid_time: 3600
state: latest
name: "*"
when: ansible_os_family == "Debian"
- name: reboot
ansible.builtin.reboot:
- name: wait for node to be ready
become: false
kubernetes.core.k8s_info:
kind: Node
name: "{{ inventory_hostname }}"
wait: yes
wait_condition:
type: Ready
status: True
delegate_to: 127.0.0.1
- name: uncordon hosts
become: false
environment:
KUBECONFIG: "{{ lookup('env', 'KUBECONFIG') }}"
kubernetes.core.k8s_drain:
name: "{{ inventory_hostname }}"
state: uncordon
delegate_to: 127.0.0.1
- name: system updates
hosts: k8s-control-plane
become: true
serial: 1
tasks:
- name: print host
become: false
debug:
var: inventory_hostname
- name: drain hosts
become: false
environment:
KUBECONFIG: "{{ lookup('env', 'KUBECONFIG') }}"
kubernetes.core.k8s_drain:
name: "{{ inventory_hostname }}"
delete_options:
delete_emptydir_data: true
ignore_daemonsets: true
terminate_grace_period: 0
delegate_to: 127.0.0.1
- name: update packages
ansible.builtin.shell: yum update -y --disablerepo=kubernetes
when: ansible_os_family == "RedHat"
- name: update debian/ubuntu packages
ansible.builtin.apt:
update_cache: yes
cache_valid_time: 3600
state: latest
name: "*"
when: ansible_os_family == "Debian"
- name: reboot
ansible.builtin.reboot:
- name: wait for node to be ready
become: false
kubernetes.core.k8s_info:
kind: Node
name: "{{ inventory_hostname }}"
wait: yes
wait_condition:
type: Ready
status: True
delegate_to: 127.0.0.1
- name: uncordon hosts
become: false
environment:
KUBECONFIG: "{{ lookup('env', 'KUBECONFIG') }}"
kubernetes.core.k8s_drain:
name: "{{ inventory_hostname }}"
state: uncordon
delegate_to: 127.0.0.1