forked from kubealex/libvirt-k8s-provisioner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_container_runtimes.yml
297 lines (254 loc) · 8.74 KB
/
10_container_runtimes.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
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
---
- name: Install container runtime
hosts: k8s_nodes
become: true
vars_files:
- vars/k8s_cluster.yml
tasks:
- name: Upgrade all packages
yum:
name: '*'
state: latest
when: k8s.cluster_os == 'CentOS'
- name: Upgrade all packages
apt:
name: '*'
state: latest
when: k8s.cluster_os == 'Ubuntu'
- name: Ensure prerequisites are met.
block:
- name: Add modules to autostart
blockinfile:
path: /etc/modules-load.d/k8s.conf
block: |
overlay
br_netfilter
create: true
- name: Enable br_netfilter
modprobe:
name: "{{ item }}"
state: present
loop:
- br_netfilter
- overlay
- name: Enable iptables inspection on bridge ifaces
blockinfile:
path: /etc/sysctl.d/k8s.conf
block: |
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
create: true
- name: Reload sysctl
shell: sysctl --system
- name: Configure docker on a Ubuntu machine
block:
- name: Ensure required packages are present
apt:
name:
- apt-transport-https
- ca-certificates
- gnupg2
- curl
- software-properties-common
state: latest
- name: Add docker repo key
apt_key:
url: "{{ docker.ubuntu.docker_repo_key }}"
keyring: "{{ docker.ubuntu.docker_repo_key_file }}"
state: present
- name: Ensure the presence of apt-repo for docker
apt_repository:
repo: "{{ docker.ubuntu.docker_repo }}"
# update_cache_retries: 25
state: present
- name: Ensure docker packages are installed
apt:
name: "{{ docker.ubuntu.docker_packages }}"
state: present
when:
- k8s.container_runtime == 'docker'
- k8s.cluster_os == 'Ubuntu'
- name: Configure docker on a CentOS machine
block:
- name: Ensure required packages are present
yum:
name:
- yum-utils
- device-mapper-persistent-data
- lvm2
state: latest
- name: Add docker repository
get_url:
url: "{{ docker.centos.docker_repo }}"
dest: "/etc/yum.repos.d/docker-ce.repo"
- name: Ensure docker is installed
yum:
name: "{{ docker.centos.docker_packages }}"
state: latest
when:
- k8s.container_runtime == 'docker'
- k8s.cluster_os == 'CentOS'
- name: Ensure docker service is configured
block:
- name: Create /etc/docker
file:
state: directory
path: /etc/docker
- name: Copy docker configuration in /etc/docker
copy:
src: files/daemon.json
dest: /etc/docker/
- name: Create systemd folder for Docker service
file:
path: /etc/systemd/system/docker.service.d
state: directory
- name: Force systemd to reread configs
systemd:
daemon_reload: yes
- name: Ensure docker is enabled and started
systemd:
name: docker
state: restarted
enabled: true
when: k8s.container_runtime == 'docker'
- name: Install cri-o
block:
- name: Add crio repo key
apt_key:
url: "{{ item.key }}"
keyring: "{{ item.keyring }}"
state: present
loop:
- key: "{{ crio.ubuntu.libcontainers_key }}"
keyring: "{{ crio.ubuntu.libcontainers_keyring }}"
- key: "{{ crio.ubuntu.crio_key }}"
keyring: "{{ crio.ubuntu.crio_keyring }}"
when: k8s.cluster_os == 'Ubuntu'
- name: Ensure the presence of apt-repo for cri-o
apt_repository:
repo: "{{ item.repo }}"
filename: "{{ item.file }}"
# update_cache_retries: 25
state: present
loop:
- repo: "{{ crio.ubuntu.libcontainers_repo }}"
file: /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
- repo: "{{ crio.ubuntu.crio_repo }}"
file: /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:1.19.list
when: k8s.cluster_os == 'Ubuntu'
- name: Add kubic CentOS repository
get_url:
url: "{{ item.url }}"
dest: "{{ item.file }}"
validate_certs: false
loop:
- file: "/etc/yum.repos.d/devel:kubic:libcontainers:stable.repo"
url: "{{ crio.centos.libcontainers_repo }}"
- file: "/etc/yum.repos.d/devel:kubic:libcontainers:stable:cri-o.repo"
url: "{{ crio.centos.crio_repo }}"
when: k8s.cluster_os == 'CentOS'
- name: Ensure cri-o is installed - CentOS
yum:
name: cri-o
state: latest
when: k8s.cluster_os == 'CentOS'
- name: Ensure cri-o is installed - Ubuntu
apt:
name:
- cri-o
- cri-o-runc
state: latest
when: k8s.cluster_os == 'Ubuntu'
- name: Fire crio-conf template
template:
src: templates/crio.conf.j2
dest: /etc/crio/crio.conf
# - name: Ensure systemd as default cgroup_manager
# replace:
# path: /etc/crio/crio.conf
# regexp: '^cgroup_manager.*'
# replace: 'cgroup_manager = "systemd"'
# - name: Ensure systemd as default cgroup_manager
# replace:
# path: /etc/crio/crio.conf
# regexp: '^conmon_cgroup.*'
# replace: 'conmon_cgroup = "pod"'
# - name: Add capabilities due to particular capabilities required by Rancher
# block:
# - name: Ensure MKNOD is enabled if installing Rancher
# lineinfile:
# path: /etc/crio/crio.conf
# line: '"MKNOD",'
# insertafter: 'default_capabilities'
# when: rancher.install_rancher
# - name: Ensure to use all possible plugins dir
# replace:
# path: /etc/crio/crio.conf
# regexp: '"/usr/libexec/cni",'
# replace: '"/usr/libexec/cni", "/opt/cni/bin/",'
# - name: Add docker.io to registries due to bad usage of unqualified images from many dev teams
# lineinfile:
# path: /etc/crio/crio.conf
# regexp: '^#registries'
# line: 'registries = [ "docker.io", "quay.io" ]'
- name: Remove example CNI configs
file:
path: "/etc/cni/net.d/{{ item }}"
state: absent
loop:
- 100-crio-bridge.conf
- 200-loopback.conf
- name: Force systemd to reread configs
systemd:
daemon_reload: yes
- name: Ensure cri-o is enabled and started
systemd:
name: crio
state: started
enabled: true
when: k8s.container_runtime == 'crio'
- name: Ensure containerd is configured and installed on CentOS machine
block:
- name: Ensure required packages are present
yum:
name:
- yum-utils
- device-mapper-persistent-data
- lvm2
state: latest
- name: Add containerd repository
get_url:
url: "{{ containerd.containerd_repo }}"
dest: "/etc/yum.repos.d/docker-ce.repo"
- name: Ensure containerd is installed
yum:
name: containerd.io
state: latest
when:
- k8s.container_runtime == 'containerd'
- k8s.cluster_os == 'CentOS'
- name: Ensure containerd is configured and installed on Ubuntu machine
apt:
name: containerd
state: latest
when:
- k8s.container_runtime == 'containerd'
- k8s.cluster_os == 'Ubuntu'
- name: Ensure containerd service is configured
block:
- name: Create /etc/containers
file:
state: directory
path: /etc/containerd
- name: Initialize config
shell: containerd config default > /etc/containerd/config.toml
- name: Force systemd to reread configs
systemd:
daemon_reload: yes
- name: Ensure containerd is enabled and started
systemd:
name: containerd
state: restarted
enabled: true
when: k8s.container_runtime == 'containerd'