-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkube_drain.yml
71 lines (61 loc) · 2.41 KB
/
kube_drain.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
#!/usr/bin/env ansible-playbook
---
# This playbook will upgrade kubernetes nodes
#
- name: "Drain Node"
hosts: kube-node:kube-master
serial: 1
remote_user: username
become: yes
become_method: sudo
tasks:
- name: Mark node "{{ inventory_hostname|lower }}" as Unschedulable.
kubernetes.core.k8s_drain:
state: cordon
kubeconfig: ~/.kube/config
name: "{{ inventory_hostname|lower }}"
delegate_to: localhost
# - name: "Drain node {{ inventory_hostname|lower }}, even if there are pods not managed by a ReplicationController, Job, or DaemonSet on it."
# kubernetes.core.k8s_drain:
# state: drain
# name: "{{ inventory_hostname|lower }}"
# kubeconfig: ~/.kube/config
# delete_options:
# ignore_daemonsets: yes
# delete_emptydir_data: yes
# force: yes
# terminate_grace_period: 0
# wait_sleep: 120
# delegate_to: localhost
## Unable to use: --pod-selector option at this moment. This part will fail is Longhorg in use.
## I will leave this commented, maybe needed one day.
- name: "Drain node {{ inventory_hostname|lower }}, even if there are pods not managed by a ReplicationController, Job, or DaemonSet on it."
shell: kubectl drain {{ inventory_hostname|lower }} --ignore-daemonsets --delete-emptydir-data --force --pod-selector='app!=csi-attacher,app!=csi-provisioner' --kubeconfig ~/.kube/config
become_user: user
delegate_to: localhost
- name: Pause for 2 minute to relocate PODs'
pause:
minutes: 2
- name: "Upgrade the OS (apt-get dist-upgrade) on {{ inventory_hostname|lower }}"
apt:
update_cache: yes
upgrade: dist
- name: "Remove useless packages from the cache from {{ inventory_hostname|lower }}"
apt:
autoclean: yes
- name: "Remove dependencies that are no longer required from {{ inventory_hostname|lower }}"
apt:
autoremove: yes
- name: Check if reboot required
stat:
path: /var/run/reboot-required
register: reboot_required_file
- name: Reboot if required
reboot:
when: reboot_required_file.stat.exists == true
- name: Mark node "{{ inventory_hostname|lower }}" as schedulable.
kubernetes.core.k8s_drain:
state: uncordon
kubeconfig: ~/.kube/config
name: "{{ inventory_hostname|lower }}"
delegate_to: localhost