-
Notifications
You must be signed in to change notification settings - Fork 6
/
k8s.yaml
306 lines (289 loc) · 8.36 KB
/
k8s.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
301
302
303
304
305
306
---
apiVersion: v1
kind: ConfigMap
metadata:
name: booty-config
data:
# Update Hardware with your MAC/Hostname mapping. Here's mine for an example
ignition.yaml: |
variant: flatcar
version: 1.1.0
passwd:
users:
- name: core
ssh_authorized_keys: [] # Add your SSH keys here
storage:
filesystems:
- device: /dev/sda
format: ext4
path: /var/lib/containerd
wipe_filesystem: true
label: ssd
files:
- path: /etc/hostname
mode: 0644
contents:
inline: {{ .Hostname }}
- path: /opt/cni.sh
contents:
source: http://192.168.50.20/data/config/cni.sh
mode: 0775
- path: /opt/systemd.sh
contents:
source: http://192.168.50.20/data/config/systemd.sh
mode: 0775
- path: /opt/kube-tools.sh
contents:
source: http://192.168.50.20/data/config/kube-tools.sh
mode: 0775
- path: /opt/join.sh
contents:
source: http://192.168.50.20/data/config/join.sh
mode: 0775
- path: /opt/version-check.sh
contents:
source: http://192.168.50.20/data/config/version-check.sh
mode: 0775
systemd:
units:
- name: var-lib-containerd.mount
enabled: true
contents: |
[Unit]
Description=Mount ephemeral to /var/lib/containerd
Before=local-fs.target
[Mount]
What=/dev/disk/by-label/ssd
Where=/var/lib/containerd
Type=ext4
[Install]
WantedBy=local-fs.target
- enabled: true
name: containerd.service
dropins:
- name: 10-wait-containerd.conf
contents: |
[Unit]
After=var-lib-containerd.mount
Requires=var-lib-containerd.mount
- name: update.service
contents: |
[Unit]
Description=Compares current version to remote version
[Service]
Environment="BOOTY_IP={{ .ServerIP }}"
Type=oneshot
ExecStart=/opt/version-check.sh
- name: update.timer
enabled: true
contents: |
[Unit]
Description=Run update-check every 10 minutes
[Timer]
OnCalendar=*:0/10
[Install]
WantedBy=multi-user.target
- enabled: true
name: cni-install.service
contents: |
[Install]
WantedBy=multi-user.target
[Unit]
Description=k8s installation script
Wants=network-online.target
After=network.target network-online.target
[Service]
Type=oneshot
ExecStart=/opt/cni.sh
- enabled: true
name: kube-tools-install.service
contents: |
[Install]
WantedBy=multi-user.target
[Unit]
Description=k8s installation script
Requires=cni-install.service
After=cni-install.service
[Service]
Type=oneshot
ExecStart=/opt/kube-tools.sh
- enabled: true
name: systemd-k8s-setup.service
contents: |
[Install]
WantedBy=multi-user.target
[Unit]
Description=k8s installation script
Requires=kube-tools-install.service
After=kube-tools-install.service
[Service]
Type=oneshot
ExecStart=/opt/systemd.sh
- enabled: true
name: k8s-join.service
contents: |
[Install]
WantedBy=multi-user.target
[Unit]
Description=k8s join script
Requires=systemd-k8s-setup.service
After=systemd-k8s-setup.service
[Service]
Environment="JOIN_STRING={{ .JoinString }}"
Type=oneshot
ExecStart=/bin/bash -c 'PATH=/opt/bin:$PATH exec /opt/join.sh'
cni.sh: |
#!/bin/bash
CNI_VERSION="v1.1.1"
mkdir -p /opt/cni/bin
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz
echo "CNI driver installed";
join.sh: |
#!/bin/bash
sysctl net.bridge.bridge-nf-call-iptables=1
/opt/bin/${JOIN_STRING}
kube-tools.sh: |
#!/bin/bash
RELEASE="$(curl -sSL https://cdn.dl.k8s.io/release/stable.txt)"
mkdir -p /opt/bin
cd /opt/bin
curl -L --remote-name-all https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/amd64/{kubeadm,kubelet,kubectl}
chmod +x {kubeadm,kubelet,kubectl}
VERSION="v1.22.0"
wget https://github.com/kubernetes-incubator/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz
sudo tar zxvf crictl-$VERSION-linux-amd64.tar.gz -C /opt/bin
rm -f crictl-$VERSION-linux-amd64.tar.gz
echo "Kube Tools installed.";
systemd.sh: |
#!/bin/bash
curl -sSL "https://raw.githubusercontent.com/kubernetes/release/master/cmd/krel/templates/latest/kubelet/kubelet.service" | sed "s:/usr/bin:/opt/bin:g" > /etc/systemd/system/kubelet.service
mkdir -p /etc/systemd/system/kubelet.service.d
curl -sSL "https://raw.githubusercontent.com/kubernetes/release/master/cmd/krel/templates/latest/kubeadm/10-kubeadm.conf" | sed "s:/usr/bin:/opt/bin:g" > /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
echo "KUBELET_EXTRA_ARGS=--cgroup-driver=systemd" > /etc/default/kubelet
systemctl enable kubelet && systemctl start kubelet
echo "Kubelet started";
version-check.sh: |
#!/bin/bash
set -a
. /etc/lsb-release
. <(curl http://${BOOTY_IP}/version.txt)
set +a
echo "Local version: $DISTRIB_RELEASE";
echo "Remote version: $FLATCAR_VERSION";
if [ "$DISTRIB_RELEASE" != "$FLATCAR_VERSION" ]; then
echo "Need to reboot!";
touch /var/run/reboot-required
else
echo "Up to date";
fi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: booty
labels:
app: booty
spec:
replicas: 1
nodeSelector:
node-role.kubernetes.io/control-plane: ""
strategy:
type: Recreate
selector:
matchLabels:
app: booty
template:
metadata:
labels:
app: booty
spec:
containers:
- args:
- --dataDir
- /data
- --serverIP
- YOUR IP ADDRESS HERE
- --httpPort
- "80"
- --debug
- --joinString
- YOUR JOIN STRING HERE
- --flatcarChannel
- beta
- --coreOSChannel
- testing
image: ghcr.io/jeefy/booty:main
imagePullPolicy: Always
name: booty
ports:
- containerPort: 69
hostPort: 69
protocol: TCP
- containerPort: 80
hostPort: 80
protocol: TCP
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: 500m
memory: 1Gi
volumes:
- name: booty-config
configMap:
name: booty-config
- name: booty-data
persistentVolumeClaim:
claimName: booty-data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: booty-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: Service
metadata:
annotations:
metallb.universe.tf/allow-shared-ip: booty-svc # If you have a metallb setup, you need this to attach two services to the same IP
labels:
app: booty
name: booty-tcp
spec:
externalTrafficPolicy: Local
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
selector:
app: booty
type: LoadBalancer
loadBalancerIP: 192.168.50.20 # This should be the IP of the service your hosts can connect to
---
apiVersion: v1
kind: Service
metadata:
annotations:
metallb.universe.tf/allow-shared-ip: booty-svc # If you have a metallb setup, you need this to attach two services to the same IP
labels:
app: booty
name: booty-udp
spec:
externalTrafficPolicy: Local
ports:
- name: tftp
port: 69
protocol: UDP
targetPort: 69
selector:
app: booty
type: LoadBalancer
loadBalancerIP: 192.168.50.20 # This should be the IP of the service your hosts can connect to