-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfull_kubevirt.yaml
300 lines (274 loc) · 10.9 KB
/
full_kubevirt.yaml
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
---
- hosts: localhost
gather_facts: false
become: false
vars_files:
- vars/config.yaml
vars_prompt:
- name: cluster_name
prompt: Specify cluster name
private: false
tasks:
- name: Destroy Full cluster
when: action == "delete" or action == "destroy"
block:
- name: Delete the service (type LoadBalancer) for Full masters
kubernetes.core.k8s:
state: absent
api_version: v1
kind: Service
namespace: "{{ ocp_namespace }}"
name: "{{ ocp_vmname_master_prefix }}-svc"
- name: Delete the service (type LoadBalancer) for Full workers
kubernetes.core.k8s:
state: absent
api_version: v1
kind: Service
namespace: "{{ ocp_namespace }}"
name: "{{ ocp_vmname_worker_prefix }}-svc"
- name: Delete A dns record
amazon.aws.route53:
state: absent
zone: "{{ dns_zone }}"
record: "{{ item }}.{{ cluster_name}}.{{ cluster_domain }}"
type: A
loop:
- "api"
- "*.apps"
- name: Delete a Full VM - masters
kubevirt.core.kubevirt_vm:
name: "{{ ocp_vmname_master_prefix }}-{{ _index }}"
namespace: "{{ ocp_namespace }}"
state: absent
loop: "{{ query('sequence', 'start=1 end=3') }}"
loop_control:
loop_var: _index
- name: Delete a Full VM - workers
kubevirt.core.kubevirt_vm:
name: "{{ ocp_vmname_worker_prefix }}-{{ _index }}"
namespace: "{{ ocp_namespace }}"
state: absent
loop: "{{ query('sequence', 'start=1 end=3') }}"
loop_control:
loop_var: _index
- name: Remove Assisted Installer Cluster
agonzalezrh.install_openshift.delete_cluster:
cluster_id: "{{ cluster_id }}"
offline_token: "{{ offline_token }}"
- name: Create Full cluster
when: action == "create"
block:
- name: Add the service (type LoadBalancer) for Full Clusters - masters
kubernetes.core.k8s:
definition: "{{ lookup('ansible.builtin.template', 'templates/masters_svc.yaml') }}"
wait: true
wait_timeout: 300
vars:
svcname: "{{ ocp_vmname_master_prefix }}-svc"
namespace: "{{ ocp_namespace }}"
- name: Wait for the LoadBalancer value - masters
register: full_svc_masters
kubernetes.core.k8s_info:
api_version: v1
kind: Service
name: "{{ ocp_vmname_master_prefix }}-svc"
namespace: "{{ ocp_namespace }}"
until: full_svc_masters.resources[0].status.loadBalancer.ingress[0].ip | default('') != ''
retries: 10
delay: 2
- name: Add A dns record - masters
amazon.aws.route53:
state: present
overwrite: true
zone: "{{ dns_zone }}"
record: "{{ item }}.{{ cluster_name}}.{{ cluster_domain }}"
type: A
value: "{{ full_svc_masters.resources[0].status.loadBalancer.ingress[0].ip }}"
ttl: 30
loop:
- "api"
- name: Add the service (type LoadBalancer) for Full Clusters - workers
kubernetes.core.k8s:
definition: "{{ lookup('ansible.builtin.template', 'templates/workers_svc.yaml') }}"
wait: true
wait_timeout: 300
vars:
svcname: "{{ ocp_vmname_worker_prefix }}-svc"
namespace: "{{ ocp_namespace }}"
- name: Wait for the LoadBalancer value - workers
register: full_svc_workers
kubernetes.core.k8s_info:
api_version: v1
kind: Service
name: "{{ ocp_vmname_worker_prefix }}-svc"
namespace: "{{ ocp_namespace }}"
until: full_svc_workers.resources[0].status.loadBalancer.ingress[0].ip | default('') != ''
retries: 10
delay: 2
- name: Add A dns record - masters
amazon.aws.route53:
state: present
overwrite: true
zone: "{{ dns_zone }}"
record: "{{ item }}.{{ cluster_name}}.{{ cluster_domain }}"
type: A
value: "{{ full_svc_workers.resources[0].status.loadBalancer.ingress[0].ip }}"
ttl: 30
loop:
- "*.apps"
- name: Create OVN secondary network
kubernetes.core.k8s:
definition: "{{ lookup('ansible.builtin.template', 'templates/net-attach-def.yaml') }}"
wait: true
wait_timeout: 300
vars:
network_name: "{{ cluster_name }}-openshift"
namespace: "{{ ocp_namespace }}"
- name: Create Assisted Installer Cluster
agonzalezrh.install_openshift.create_cluster:
name: "{{ cluster_name }}"
openshift_version: "{{ cluster_version }}"
base_dns_domain: "{{ cluster_domain }}"
offline_token: "{{ offline_token }}"
pull_secret: "{{ pull_secret }}"
high_availability_mode: "Full"
schedulable_masters: false
service_networks:
- cidr: "172.31.0.0/16"
machine_networks:
- cidr: "{{ network_prefix }}.0/24"
api_vip: "{{ network_prefix }}.100"
api_vips:
- ip: "{{ network_prefix }}.100"
ingress_vip: "{{ network_prefix }}.101"
ingress_vips:
- ip: "{{ network_prefix }}.101"
register: newcluster
- name: Include vars
include_vars:
file: vars/static_network_config_full.yaml
- name: Create Infrastructure environment
agonzalezrh.install_openshift.create_infra_env:
name: "{{ cluster_name }}-infra-env"
image_type: "{{ cluster_iso_type }}"
cluster_id: "{{ newcluster.result.id }}"
ssh_authorized_key: "{{ ssh_authorized_key }}"
offline_token: "{{ offline_token }}"
pull_secret: "{{ pull_secret }}"
static_network_config: "{{ static_network_config }}"
register: newinfraenv
- name: Create a three master VMs for Full cluster
include_tasks: tasks/kubevirt/create_masters.yaml
vars:
image_url: "{{ newinfraenv.result.download_url }}"
vmname: "{{ ocp_vmname_master_prefix }}-{{ _index }}"
namespace: "{{ ocp_namespace }}"
storageclass: "{{ storage_class }}"
network: "{{ cluster_name}}-openshift"
network_name: "{{ cluster_name }}-openshift"
pod_network: "192.168.{{ _index }}.0/24"
loop: "{{ query('sequence', 'start=1 end=3') }}"
loop_control:
loop_var: _index
- name: Create a three worker VMs for Full cluster
include_tasks: tasks/kubevirt/create_workers.yaml
vars:
image_url: "{{ newinfraenv.result.download_url }}"
vmname: "{{ ocp_vmname_worker_prefix }}-{{ _index }}"
namespace: "{{ ocp_namespace }}"
storageclass: "{{ storage_class }}"
network: "{{ cluster_name}}-openshift"
network_name: "{{ cluster_name }}-openshift"
pod_network: "192.168.1{{ _index }}.0/24"
loop: "{{ query('sequence', 'start=1 end=3') }}"
loop_control:
loop_var: _index
- name: Wait for the hosts to be ready
agonzalezrh.install_openshift.wait_for_hosts:
cluster_id: "{{ newcluster.result.id }}"
offline_token: "{{ offline_token }}"
expected_hosts: 6
infra_env_id: "{{ newinfraenv.result.id }}"
configure_hosts:
- hostname: master-{{ cluster_name }}-1
role: master
- hostname: master-{{ cluster_name }}-2
role: master
- hostname: master-{{ cluster_name }}-3
role: master
- hostname: worker-{{ cluster_name }}-1
role: worker
- hostname: worker-{{ cluster_name }}-2
role: worker
- hostname: worker-{{ cluster_name }}-3
role: worker
wait_timeout: 600
- name: Start cluster installation
agonzalezrh.install_openshift.install_cluster:
cluster_id: "{{ newcluster.result.id }}"
offline_token: "{{ offline_token }}"
wait_timeout: 1200
- name: Obtain OpenShift cluster credentials
register: credentials
agonzalezrh.install_openshift.get_credentials:
cluster_id: "{{ newcluster.result.id }}"
offline_token: "{{ offline_token }}"
- name: Display credentials
debug:
var: credentials.result
- name: Create directory for downloaded credential files
ansible.builtin.file:
state: directory
path: "{{ output_dir }}/{{ cluster_name }}"
recurse: true
- name: Downloads OpenShift cluster credentials
agonzalezrh.install_openshift.download_credentials:
cluster_id: "{{ newcluster.result.id }}"
offline_token: "{{ offline_token }}"
file_name: "{{ item }}"
dest: "{{ output_dir }}/{{ cluster_name }}/{{ item }}"
loop:
- kubeadmin-password
- kubeconfig
- kubeconfig-noingress
- name: Scale router pod to the number of workers
environment:
KUBECONFIG: "{{ output_dir }}/{{ cluster_name }}/kubeconfig"
kubernetes.core.k8s:
state: patched
kind: IngressController
name: default
namespace: openshift-ingress-operator
merge_type: merge
definition:
spec:
replicas: 3
- name: Configure OVN-Kubernetes to switch to local gateway mode
environment:
KUBECONFIG: "{{ output_dir }}/{{ cluster_name }}/kubeconfig"
kubernetes.core.k8s:
state: patched
api_version: operator.openshift.io/v1
kind: Network
name: cluster
merge_type: merge
definition:
spec:
defaultNetwork:
ovnKubernetesConfig:
gatewayConfig:
routingViaHost: true
- name: Downloads OpenShift cluster files
agonzalezrh.install_openshift.download_files:
cluster_id: "{{ newcluster.result.id }}"
offline_token: "{{ offline_token }}"
file_name: "{{ item }}"
dest: "{{ output_dir }}/{{ cluster_name }}/{{ item }}"
loop:
- bootstrap.ign
- master.ign
- metadata.json
- worker.ign
- install-config.yaml
- custom_manifests.json
- custom_manifests.yaml