-
Notifications
You must be signed in to change notification settings - Fork 107
/
kubernetes.yml
77 lines (66 loc) · 2.79 KB
/
kubernetes.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
---
- name: K8s/{{ node_role }} | Wait for kube-apiserver
delegate_to: >-
{{ inventory_hostname if inventory_hostname in groups.kubernetes_master else
groups.kubernetes_master[0] }}
import_tasks: kubernetes/utils/wait-for-kube-apiserver.yml
# During HA control plane upgrade server address in kubeconfig is switched to local for
# * compatibility between client and server versions
# * identifying correct server version
- name: K8s/{{ node_role }} | Switch apiserver address to local
include_tasks: kubernetes/utils/set-local-apiserver.yml # sets kubectl_context_cluster
when:
- groups.kubernetes_master | length > 1
- inventory_hostname in groups.kubernetes_master
- name: K8s/{{ node_role }} | Include get-kubelet-version.yml
import_tasks: kubernetes/get-kubelet-version.yml
delegate_to: "{{ groups.kubernetes_master[0] }}"
- name: K8s/{{ node_role }} | Set kubelet version as fact
set_fact:
initial_kubelet_version: "{{ kubelet_version.stdout }}"
- name: K8s/{{ node_role }} | Check if upgrade state file exists
stat:
path: "{{ kubernetes.upgrade_state_file_path }}"
get_attributes: false
get_checksum: false
get_mime: false
register: k8s_upgrade_state_file_status
- name: Upgrade masters then nodes
vars:
version: "{{ ver }}"
cni_version: "{{ cni_ver }}"
when:
- k8s_upgrade_state_file_status.stat.exists
or initial_kubelet_version is version('v' + version, '<')
block:
- name: K8s/{{ node_role }} | Create K8s upgrade state file
copy:
dest: "{{ kubernetes.upgrade_state_file_path }}"
content: Upgrade started
mode: u=rw,g=r,o=
- name: K8s/{{ node_role }} | Upgrade first master to v{{ version }}
include_tasks: kubernetes/upgrade-master0.yml
when:
- inventory_hostname == groups.kubernetes_master[0]
- name: K8s/{{ node_role }} | Upgrade next master to v{{ version }}
include_tasks: kubernetes/upgrade-masterN.yml
when:
- inventory_hostname in groups.kubernetes_master[1:]
- name: K8s/{{ node_role }} | Upgrade node to v{{ version }}
when:
- groups.kubernetes_node is defined
- inventory_hostname in groups.kubernetes_node
include_tasks: kubernetes/upgrade-node.yml
- name: K8s/{{ node_role }} | Remove K8s upgrade state file
file:
path: "{{ kubernetes.upgrade_state_file_path }}"
state: absent
- name: K8s/{{ node_role }} | Switch apiserver address to HAProxy
command: |-
kubectl config set-cluster {{ kubectl_context_cluster.stdout }} --server=https://localhost:3446
when:
- groups.kubernetes_master | length > 1
- inventory_hostname in groups.kubernetes_master
changed_when: true
- name: K8s/{{ node_role }} | Upgrade internal haproxy load-balancer
import_tasks: kubernetes/upgrade-haproxy.yml