-
Notifications
You must be signed in to change notification settings - Fork 1
/
daemonset.yaml
293 lines (285 loc) · 7.31 KB
/
daemonset.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
apiVersion: v1
kind: ServiceAccount
metadata:
name: wireguard-agent
namespace: kube-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: wireguard-agent
rules:
- apiGroups:
- ""
resources:
- nodes
verbs:
- list
- watch
- get
- update
- apiGroups:
- authentication.k8s.io
resources:
- tokenreviews
verbs:
- create
- apiGroups:
- authorization.k8s.io
resources:
- subjectaccessreviews
verbs:
- create
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: wireguard-agent
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: wireguard-agent
subjects:
- kind: ServiceAccount
name: wireguard-agent
namespace: kube-system
---
apiVersion: v1
kind: ConfigMap
metadata:
name: install-wireguard-script
namespace: kube-system
data:
install.sh: |
#!/usr/bin/env bash
set -euo pipefail
if [[ -x "$(command -v wg)" ]]; then
echo "WireGuard is already installed"
exit 0
fi
OS=$(lsb_release -d | awk -F"\t" '{print $2}')
if [[ ${OS} != *"Ubuntu 18.04"* ]]; then
echo "Not Ubuntu 18.04 - Won't install WireGuard"
exit 1
fi
if ! [[ -x "$(command -v add-apt-repository)" ]]; then
apt update
apt install -y software-properties-common
fi
if [[ ! -f "/etc/apt/sources.list.d/wireguard-ubuntu-wireguard-bionic.list" ]]; then
add-apt-repository -y ppa:wireguard/wireguard
fi
# In case something got canceled
dpkg --configure -a
# Make sure we have headers for all future and our current kernel
apt install -y linux-headers-generic linux-headers-$(uname -r)
apt install -y wireguard
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cni-tpl
namespace: kube-system
data:
10-bridge.conflist: |
{
"cniVersion": "0.3.1",
"name": "wg",
"plugins": [
{
"type": "bridge",
"bridge": "cni0",
"isGateway": true,
"isDefaultGateway": true,
"ipMasq": true,
"hairpinMode": true,
"mtu": {{ .MTU }},
"ipam": {
"type": "host-local",
"ranges": [
[
{
"subnet": "{{ .NodePodCIDR }}"
}
]
]
}
},
{
"type": "portmap",
"capabilities": {
"portMappings": true
}
},
{
"type": "bandwidth",
"capabilities": {
"bandwidth": true
}
}
]
}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: wireguard-agent
namespace: kube-system
spec:
updateStrategy:
type: RollingUpdate
selector:
matchLabels:
app: wireguard-agent
template:
metadata:
labels:
app: wireguard-agent
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8082"
prometheus.io/path: /metrics
prometheus.io/scheme: "https"
spec:
priorityClassName: system-node-critical
serviceAccountName: wireguard-agent
hostPID: true
hostNetwork: true
tolerations:
- operator: Exists
effect: NoSchedule
initContainers:
- name: copy-install-script
image: quay.io/mrincompetent/wireguard-controller:v0.1.6
resources:
requests:
cpu: "25m"
memory: "32Mi"
limits:
cpu: "25m"
memory: "32Mi"
command:
# We have to copy the script to the host to have it accessible when using nsenter
- /bin/cp
args: [
"/install-script/install.sh",
"/etc/wireguard/install_wireguard.sh",
]
volumeMounts:
- name: wireguard
mountPath: /etc/wireguard
- name: install-script
mountPath: /install-script
- name: install-wireguard
image: quay.io/mrincompetent/wireguard-controller:v0.1.6
resources:
requests:
cpu: "500m"
memory: "500Mi"
limits:
cpu: "500m"
memory: "500Mi"
securityContext:
privileged: true
command:
- /usr/bin/nsenter
args: [
"-t", "1",
"-m",
"-u",
"-i",
"-n",
"-p",
"--",
"/bin/bash", "/etc/wireguard/install_wireguard.sh",
]
- name: install-cni-plugins
image: quay.io/mrincompetent/wireguard-controller:v0.1.6
resources:
requests:
cpu: "25m"
memory: "32Mi"
limits:
cpu: "25m"
memory: "32Mi"
command:
- /bin/sh
args:
- "-c"
- "cp /cni-bin/* /opt/cni/bin/"
volumeMounts:
- name: cni-bin
mountPath: /opt/cni/bin
containers:
- name: agent
image: quay.io/mrincompetent/wireguard-controller:v0.1.6
command:
- /wireguard-controller
args: [
"-node-name", "$(NODE_NAME)",
"-pod-cidr", "172.25.0.0/16",
"-telemetry-listen-address", "127.0.0.1:8081",
"-cni-tpl-path", "/cni-tpl/",
]
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
resources:
requests:
cpu: "25m"
memory: "64Mi"
limits:
cpu: "25m"
memory: "64Mi"
securityContext:
capabilities:
add: ["NET_ADMIN"]
readinessProbe:
exec:
command:
- "/usr/bin/wget"
- "-O -"
- "http://127.0.0.1:8081/ready"
initialDelaySeconds: 5
periodSeconds: 5
volumeMounts:
- name: wireguard
mountPath: /etc/wireguard
- name: cni-conf
mountPath: /etc/cni/net.d
- name: cni-tpl
mountPath: /cni-tpl
- args:
- --logtostderr
- --secure-listen-address=$(IP):8082
- --tls-cipher-suites=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
- --upstream=http://127.0.0.1:8081/
env:
- name: IP
valueFrom:
fieldRef:
fieldPath: status.podIP
image: quay.io/coreos/kube-rbac-proxy:v0.4.1
name: kube-rbac-proxy
ports:
- containerPort: 8082
hostPort: 8082
name: https
volumes:
- name: wireguard
hostPath:
path: /etc/wireguard
- name: cni-conf
hostPath:
path: /etc/cni/net.d
- name: cni-bin
hostPath:
path: /opt/cni/bin
- name: install-script
configMap:
name: install-wireguard-script
- name: cni-tpl
configMap:
name: cni-tpl