comparison next/create_all.py @ 55:24f4ec319f98

yaml to py
author drewp@bigasterisk.com
date Fri, 26 Apr 2024 15:55:25 -0700
parents
children a72c47973aa4
comparison
equal deleted inserted replaced
54:21185db8a52e 55:24f4ec319f98
1 import json
2 from pathlib import Path
3
4
5 def toJson(d):
6 return json.dumps(d, sort_keys=True, indent=2)
7
8
9 build = Path('build')
10 (build / 'vmagent_deploy.yaml').write_text(
11 toJson({
12 "apiVersion": "apps/v1",
13 "kind": "Deployment",
14 "metadata": {
15 "name": "next-victoriametrics-vmagent"
16 },
17 "spec": {
18 "replicas": 1,
19 "strategy": {
20 "type": "Recreate"
21 },
22 "selector": {
23 "matchLabels": {
24 "app": "next-victoriametrics-vmagent"
25 }
26 },
27 "template": {
28 "metadata": {
29 "labels": {
30 "app": "next-victoriametrics-vmagent"
31 },
32 "annotations": {
33 "prometheus.io/scrape": "true",
34 "prometheus.io/path": "/m/metrics",
35 "prometheus.io/port": "80"
36 }
37 },
38 "spec": {
39 "volumes": [{
40 "name": "config",
41 "configMap": {
42 "name": "victoriametrics-config"
43 }
44 }],
45 "serviceAccountName":
46 "victoriametrics",
47 "containers": [{
48 "name": "vmagent",
49 "image": "docker.io/victoriametrics/vmagent:v1.100.1",
50 "imagePullPolicy": "IfNotPresent",
51 "args": ["-http.pathPrefix=/m/next/vmagent/", "-loggerTimezone=America/Los_Angeles", "-promscrape.config=/local/config/scrape_main", "-promscrape.configCheckInterval=5s", "-sortLabels", "-remoteWrite.url=http://next-victoriametrics-vminsert/m/next/vminsert/insert/0/prometheus/api/v1/write", "-remoteWrite.showURL"],
52 "ports": [{
53 "containerPort": 8429
54 }],
55 "volumeMounts": [{
56 "name": "config",
57 "mountPath": "/local/config"
58 }]
59 }]
60 }
61 }
62 }
63 }))
64 (build / 'vmagent_svc.yaml').write_text(toJson({"apiVersion": "v1", "kind": "Service", "metadata": {"name": "next-victoriametrics-vmagent"}, "spec": {"ports": [{"port": 80, "targetPort": 8429}], "selector": {"app": "next-victoriametrics-vmagent"}}}))
65
66 (build / 'vminsert_deploy.yaml').write_text(
67 toJson({
68 "apiVersion": "apps/v1",
69 "kind": "Deployment",
70 "metadata": {
71 "name": "next-victoriametrics-vminsert"
72 },
73 "spec": {
74 "replicas": 1,
75 "strategy": {
76 "type": "Recreate"
77 },
78 "selector": {
79 "matchLabels": {
80 "app": "next-victoriametrics-vminsert"
81 }
82 },
83 "template": {
84 "metadata": {
85 "labels": {
86 "app": "next-victoriametrics-vminsert"
87 },
88 "annotations": {
89 "prometheus.io/scrape": "true",
90 "prometheus.io/path": "/m/metrics",
91 "prometheus.io/port": "80"
92 }
93 },
94 "spec": {
95 "serviceAccountName": "victoriametrics",
96 "containers": [{
97 "name": "vminsert",
98 "image": "docker.io/victoriametrics/vminsert:v1.100.1-cluster",
99 "imagePullPolicy": "IfNotPresent",
100 "args": ["-http.pathPrefix=/m/next/vminsert/", "-loggerTimezone=America/Los_Angeles", "-storageNode=next-victoriametrics-vmstorage"],
101 "ports": [{
102 "containerPort": 8480
103 }]
104 }]
105 }
106 }
107 }
108 }))
109 (build / 'vminsert_svc.yaml').write_text(toJson({"apiVersion": "v1", "kind": "Service", "metadata": {"name": "next-victoriametrics-vminsert"}, "spec": {"ports": [{"port": 80, "targetPort": 8480}], "selector": {"app": "next-victoriametrics-vminsert"}}}))
110
111 (build / 'vmstorage_pv.yaml').write_text(
112 toJson({
113 "apiVersion": "v1",
114 "kind": "PersistentVolume",
115 "metadata": {
116 "name": "next-victoriametrics",
117 "labels": {
118 "type": "local"
119 }
120 },
121 "spec": {
122 "storageClassName": "manual",
123 "hostPath": {
124 "path": "/opt/next-victoriametrics"
125 },
126 "capacity": {
127 "storage": "50Gi"
128 },
129 "accessModes": ["ReadWriteMany"],
130 "persistentVolumeReclaimPolicy": "Retain",
131 "claimRef": {
132 "namespace": "default",
133 "name": "next-victoriametrics"
134 }
135 }
136 }))
137 (build / 'vmstorage_pvc.yaml').write_text(toJson({"apiVersion": "v1", "kind": "PersistentVolumeClaim", "metadata": {"name": "next-victoriametrics"}, "spec": {"storageClassName": "", "volumeName": "next-victoriametrics", "accessModes": ["ReadWriteMany"], "resources": {"requests": {"storage": "50Gi"}}}}))
138
139 (build / 'vmstorage_deploy.yaml').write_text(
140 toJson({
141 "apiVersion": "apps/v1",
142 "kind": "Deployment",
143 "metadata": {
144 "name": "next-victoriametrics-vmstorage"
145 },
146 "spec": {
147 "replicas": 1,
148 "strategy": {
149 "type": "Recreate"
150 },
151 "selector": {
152 "matchLabels": {
153 "app": "next-victoriametrics-vmstorage"
154 }
155 },
156 "template": {
157 "metadata": {
158 "labels": {
159 "app": "next-victoriametrics-vmstorage"
160 },
161 "annotations": {
162 "prometheus.io/scrape": "true",
163 "prometheus.io/path": "/m/vmstorage/metrics",
164 "prometheus.io/port": "80"
165 }
166 },
167 "spec": {
168 "volumes": [{
169 "name": "data",
170 "persistentVolumeClaim": {
171 "claimName": "next-victoriametrics"
172 }
173 }],
174 "serviceAccountName": "victoriametrics",
175 "containers": [{
176 "name": "vmstorage",
177 "image": "docker.io/victoriametrics/vmstorage:v1.100.1-cluster",
178 "imagePullPolicy": "IfNotPresent",
179 "args": ["-http.pathPrefix=/m/next/vmstorage/", "-loggerTimezone=America/Los_Angeles", "-retentionPeriod=100y", "-storageDataPath=/data/100y"],
180 "ports": [{
181 "containerPort": 8482,
182 "name": "http"
183 }, {
184 "containerPort": 8400,
185 "name": "vminsert"
186 }, {
187 "containerPort": 8401,
188 "name": "vmselect"
189 }],
190 "volumeMounts": [{
191 "name": "data",
192 "mountPath": "/data"
193 }]
194 }],
195 "affinity": {
196 "nodeAffinity": {
197 "requiredDuringSchedulingIgnoredDuringExecution": {
198 "nodeSelectorTerms": [{
199 "matchExpressions": [{
200 "key": "kubernetes.io/hostname",
201 "operator": "In",
202 "values": ["ditto"]
203 }]
204 }]
205 }
206 }
207 }
208 }
209 }
210 }
211 }))
212 (build / 'vmstorage_svc.yaml').write_text(toJson({"apiVersion": "v1", "kind": "Service", "metadata": {"name": "next-victoriametrics-vmstorage"}, "spec": {"ports": [{"port": 80, "targetPort": "http", "name": "http"}, {"port": 8400, "targetPort": "vminsert", "name": "vminsert"}, {"port": 8401, "targetPort": "vmselect", "name": "vmselect"}], "selector": {"app": "next-victoriametrics-vmstorage"}}}))
213
214 (build / 'vmselect_deploy.yaml').write_text(
215 toJson({
216 "apiVersion": "apps/v1",
217 "kind": "Deployment",
218 "metadata": {
219 "name": "next-victoriametrics-vmselect"
220 },
221 "spec": {
222 "replicas": 1,
223 "strategy": {
224 "type": "Recreate"
225 },
226 "selector": {
227 "matchLabels": {
228 "app": "next-victoriametrics-vmselect"
229 }
230 },
231 "template": {
232 "metadata": {
233 "labels": {
234 "app": "next-victoriametrics-vmselect"
235 },
236 "annotations": {
237 "prometheus.io/scrape": "true",
238 "prometheus.io/path": "/m/metrics",
239 "prometheus.io/port": "80"
240 }
241 },
242 "spec": {
243 "serviceAccountName": "victoriametrics",
244 "containers": [{
245 "name": "vmselect",
246 "image": "docker.io/victoriametrics/vmselect:v1.100.1-cluster",
247 "imagePullPolicy": "IfNotPresent",
248 "args": ["-http.pathPrefix=/m/next/vmselect/", "-loggerTimezone=America/Los_Angeles", "-storageNode=next-victoriametrics-vmstorage"],
249 "ports": [{
250 "containerPort": 8481
251 }]
252 }]
253 }
254 }
255 }
256 }))
257 (build / 'vmselect_svc.yaml').write_text(toJson({
258 "apiVersion": "v1",
259 "kind": "Service",
260 "metadata": {
261 "name": "next-victoriametrics-vmselect"
262 },
263 "spec": {
264 "ports": [{
265 "port": 80,
266 "targetPort": 8481
267 }],
268 "selector": {
269 "app": "next-victoriametrics-vmselect"
270 }
271 }
272 }
273 # in vmui, set server url to
274 # https://bigasterisk.com/m/next/vmselect/select/0/prometheus
275 ))
276
277 (build / 'vmselect_svc.yaml').write_text(
278 toJson({
279 "apiVersion": "networking.k8s.io/v1",
280 "kind": "Ingress",
281 "metadata": {
282 "name": "next-victoriametrics",
283 "annotations": {
284 "cert-manager.io/cluster-issuer": "letsencrypt-prod",
285 "ingress.pomerium.io/allow_public_unauthenticated_access": "false",
286 "ingress.pomerium.io/pass_identity_headers": "true",
287 "ingress.pomerium.io/preserve_host_header": "true",
288 }
289 },
290 "spec": {
291 "ingressClassName": "pomerium",
292 "rules": [{
293 "host": "bigasterisk.com",
294 "http": {
295 "paths": [{
296 "pathType": "Prefix",
297 "path": "/m/next/vmselect/",
298 "backend": {
299 "service": {
300 "name": "next-victoriametrics-vmselect",
301 "port": {
302 "number": 80
303 }
304 }
305 }
306 }, {
307 "pathType": "Prefix",
308 "path": "/m/next/vmagent/",
309 "backend": {
310 "service": {
311 "name": "next-victoriametrics-vmagent",
312 "port": {
313 "number": 80
314 }
315 }
316 }
317 }, {
318 "pathType": "Prefix",
319 "path": "/m/next/vmselect/",
320 "backend": {
321 "service": {
322 "name": "next-victoriametrics-vmselect",
323 "port": {
324 "number": 80
325 }
326 }
327 }
328 }]
329 }
330 }],
331 "tls": [{
332 "hosts": ["bigasterisk.com"],
333 "secretName": "bigasterisk.com-tls"
334 }]
335 }
336 }))