-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.yml
210 lines (182 loc) · 5.63 KB
/
main.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
- name: install necessary packages
apt:
name: "{{ packages }}"
update_cache: true
vars:
packages:
- unattended-upgrades
- tuned
- iperf3
- jq
- snapd
- bzip2
- restic
- intel-gpu-tools
- vnstat
- jnettop
# - name: remove hwe kernel (doesn't play nice)
# apt:
# name: linux-generic-hwe-22.04
# state: absent
- name: install yq via snap
snap:
name: yq
when: "inventory_hostname in groups['k3s_servers']"
- name: Allow admin SSH sources to this host
ufw:
rule: allow
port: 22
proto: tcp
src: '{{ item }}'
state: enabled
loop: "{{ firewall.admin_source }}"
- name: Allow port 5201 for occasional iperf testing (enable when necessary)
ufw:
rule: allow
port: 5201
proto: tcp
state: enabled
- name: Allow any incoming traffic to the public IP for host-port exposed services
ufw:
direction: in
rule: "allow"
port: "{{ item.port }}"
proto: "{{ item.proto }}"
with_items:
- { port: "80", proto: "tcp" } # traefik web
- { port: "443", proto: "tcp" } # traefik websecure
- name: Allow any routed traffic on the cluster NIC
ufw:
# direction: in
rule: "allow"
route: true
interface_in: "{{ cluster_nic }}"
- name: Allow any incoming traffic on the cluster NIC
ufw:
direction: in
rule: "allow"
interface: "{{ cluster_nic }}"
- name: Allow any incoming traffic to nginx-ingress-controller on the fairies from the Hetzner LB
ufw:
direction: in
rule: "allow"
port: "{{ item.port }}"
proto: "{{ item.proto }}"
src: 10.0.40.3/32 # hetzner LB
with_items:
# - { port: "7000", proto: "tcp" } # http
- { port: "7443", proto: "tcp" } # https
when:
- "inventory_hostname in groups['k3s_servers']"
- name: Allow any incoming traffic from the cluster for host-network exposed services
ufw:
direction: in
rule: "allow"
src: "10.2.0.0/15"
port: "{{ item.port }}"
proto: "{{ item.proto }}"
with_items:
- { port: "10250", proto: "tcp" } # kubelet metrics
- { port: "10257", proto: "tcp" } # kube-controller metrics
- { port: "10259", proto: "tcp" } # kube-scheduler metrics
- { port: "2381", proto: "tcp" } # k3s etcd
- { port: "9100", proto: "tcp" } # node-exporter
- { port: "6443", proto: "tcp" } # k8s-api
- { port: "3300", proto: "tcp" } # ceph-mon
- { port: "6789", proto: "tcp" } # ceph-mon
- { port: "9283", proto: "tcp" } # ceph metrics
- { port: "6800:7300", proto: "tcp" } # ceph (not sure what, but necessary for csi-provisioner)
- { port: "8080", proto: "tcp" } # kured
- { port: "7472", proto: "tcp" } # metallb
- { port: "4244", proto: "tcp" } # hubble
- name: Allow any incoming traffic into the ceph cluster network
ufw:
direction: in
rule: "allow"
src: 10.0.44.0/24
- name: Determine public NIC name (step 1/2)
set_fact:
cluster_nic_split: "{{ cluster_nic | split('.')}}"
- name: Determine public NIC name (step 2/2)
set_fact:
public_nic: "{{ cluster_nic_split.0 }}"
- name: Drop any unexpected incoming traffic hitting the hetzner public nic ({{ public_nic }}) # (this is the case anyway, but we want to avoid unnecessary logging)
ufw:
direction: in
rule: "deny"
interface: "{{ public_nic }}"
log: "false"
when: public_nic not in "eth1" # NICs work differently in ci
- name: Set tuned profile to throughput-performance
command: tuned-adm profile throughput-performance
- name: Change various sysctl-settings
sysctl:
name: '{{ item.key }}'
value: '{{ item.value }}'
sysctl_set: yes
state: present
reload: yes
ignoreerrors: yes
with_dict: '{{ sysctl_config }}'
- name: Disable swap for current session
command: swapoff -a
become: true
- name: Disable swap permanently, persist reboots
replace:
path: /etc/fstab
regexp: '^(\s*)([^#\n]+\s+)(\w+\s+)swap(\s+.*)$'
replace: '#\1\2\3swap\4'
backup: yes
- name: Create a thin pool on vg0
community.general.lvol:
vg: vg0
thinpool: thinpool
size: 100%FREE
when:
- "inventory_hostname in groups['k3s_agents'] or inventory_hostname in groups['k3s_servers'] or inventory_hostname in groups['k3s_observability']"
ignore_errors: true # so we can run it multiple times
- name: copy scripts
copy:
src: "{{ item }}"
dest: /usr/local/bin/{{ item }}
mode: u+x
loop:
- smartmon_metrics.sh
- kill-unwanted-transcodes.sh
- name: Install smartmontools
apt: pkg=smartmontools
- name: Install lm-sensors
apt: pkg=lm-sensors
- name: Ensure directory /var/lib/node-exporter/textfiles/ exists
file:
path: /var/lib/node-exporter/textfiles
state: directory
- name: Expose smartmon metrics to node-exporter
cron:
name: "smartmon metrics"
minute: "*/5"
hour: "*"
job: "/usr/local/bin/smartmon_metrics.sh > /var/lib/node-exporter/textfiles/smart_metrics.prom && chmod 644 /var/lib/node-exporter/textfiles/smart_metrics.prom"
- name: Add cron scripts to kill unwanted transcodes
cron:
name: "unwanted transcodes"
minute: "*"
hour: "*"
job: "/usr/local/bin/kill-unwanted-transcodes.sh"
- name: ignore irrelevant logs via rsyslog
copy:
src: ignore-irrelevant-logs.conf
dest: /etc/rsyslog.d/ignore-irrelevant-logs.conf
- name: update logrotate.conf
copy:
src: logrotate.conf
dest: /etc/logrotate.conf
- name: restart rsyslog
systemd:
name: rsyslog
state: restarted
enabled: yes
# - name: remove HWE kernel
# shell: |
# apt remove -y --purge linux-generic-hwe-22.04
# apt remove -y --purge linux-hwe-* linux-modules-6* linux-modules-6* linux-modules-6*