forked from opea-project/GenAIStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudio-manifest.yaml
562 lines (533 loc) · 15.6 KB
/
studio-manifest.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
---
apiVersion: v1
kind: ConfigMap
metadata:
name: studio-nginx-config
namespace: studio
data:
default.conf: |+
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
server {
# listen 80;
# listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/ssl/app-tls.crt;
ssl_certificate_key /etc/ssl/app-tls.key;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
client_max_body_size 10G;
resolver kube-dns.kube-system.svc.cluster.local valid=300s;
resolver_timeout 5s;
location /home {
root /usr/share/nginx/html;
index index.html;
}
# Location block for studio-appbuilder and app-frontend
location / {
# Initialize the default variable for namespace
set $namespace "";
# Check if the Referer contains '?ns=' and extract the ns argument
if ($http_referer ~* "([&?]ns=([^&]+))") {
set $namespace $2; # Capture the value of 'ns'
}
# If 'ns' is not in the Referer, fallback to 'arg_ns'
if ($namespace = "") {
set $namespace $arg_ns; # Use the value from the 'arg_ns'
}
# Initialize the target host
set $target_host http://${STUDIO_FRONTEND_DNS};
if ($namespace != "") {
set $target_host http://${APP_FRONTEND_DNS};
}
# Rewrite the request to include the namespace
rewrite ^/(.*)$ /$1?ns=$namespace break;
# Proxy to the desired service using the namespace
proxy_pass $target_host;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Location block for keycloak
location /auth {
proxy_pass https://${KEYCLOAK_DNS}/auth/;
proxy_set_header Host $host:30007;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Location block for app-backend
location /v1/app-backend {
# Initialize the variable for namespace
if ($http_referer ~* "([&?]ns=([^&]+))") {
set $namespace $2; # Capture the value of 'ns'
}
# Rewrite the request to include the namespace
rewrite ^/(.*)$ /$1?ns=$namespace break;
# Proxy to the desired service using the namespace
proxy_pass http://${APP_BACKEND_DNS};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Disable buffering for SSE
proxy_buffering off;
proxy_cache off;
proxy_http_version 1.1;
proxy_set_header Connection '';
chunked_transfer_encoding off;
}
# Location block for opea_service@prepare_doc_redis_prep
location /v1/dataprep {
# Initialize the variable for namespace
if ($http_referer ~* "([&?]ns=([^&]+))") {
set $namespace $2; # Capture the value of 'ns'
}
# Rewrite the request to include the namespace
rewrite ^/(.*)$ /$1?ns=$namespace break;
# Proxy to the desired service using the namespace
proxy_pass http://${PREPARE_DOC_REDIS_PREP_DNS};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Additional location block for Grafana static assets
location /grafana {
proxy_pass http://${GRAFANA_DNS};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Proxy Grafana Live WebSocket connections
location /grafana/api/live/ {
proxy_pass http://${GRAFANA_DNS};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Ensure WebSocket upgrade headers
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /studio-backend {
proxy_pass http://${STUDIO_BACKEND_DNS};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /studio-backend/ws {
proxy_pass http://${STUDIO_BACKEND_DNS}/studio-backend/ws;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Ensure WebSocket upgrade headers
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
---
apiVersion: v1
kind: Service
metadata:
name: studio-nginx
namespace: studio
spec:
selector:
app: studio-nginx
ports:
- name: https
protocol: TCP
port: 443
targetPort: 443
nodePort: 30007
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: studio-nginx
namespace: studio
labels:
app: studio-nginx
spec:
selector:
matchLabels:
app: studio-nginx
template:
metadata:
labels:
app: studio-nginx
spec:
initContainers:
- name: init-nginx
image: nginx:1.27.1
command: ["/bin/sh", "-c"]
args:
- |
envsubst "$(env | grep _DNS= | awk -F= '{print "${"$1"}"}' | tr '\n' ' ')" < /tmp/default.conf > /etc/nginx/conf.d/default.conf
envFrom:
- configMapRef:
name: studio-config
volumeMounts:
- name: tmp-volume
mountPath: /tmp
- name: nginx-conf-volume
mountPath: /etc/nginx/conf.d
containers:
- name: nginx
image: nginx:1.27.1
imagePullPolicy: IfNotPresent
volumeMounts:
- name: nginx-conf-volume
mountPath: /etc/nginx/conf.d
- name: app-tls
mountPath: /etc/ssl
securityContext: {}
volumes:
- name: tmp-volume
configMap:
defaultMode: 420
name: studio-nginx-config
- name: nginx-conf-volume
emptyDir: {}
- name: app-tls
secret:
secretName: app-tls
---
apiVersion: v1
kind: Service
metadata:
name: studio-backend
namespace: studio
spec:
type: ClusterIP
ports:
- protocol: TCP
port: 5000
targetPort: 5000
selector:
app: studio-backend
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: studio-backend-sa
namespace: studio
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: namespace-manager
rules:
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get", "create", "delete"]
- apiGroups: [""]
resources: ["services"]
verbs: ["get", "create", "list"]
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "create"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "create"]
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "create", "list"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["list", "get"]
- apiGroups: [""]
resources: ["nodes"]
verbs: ["list", "get"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "create", "list", "watch"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "create", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: namespace-manager-binding
subjects:
- kind: ServiceAccount
name: studio-backend-sa
namespace: studio
roleRef:
kind: ClusterRole
name: namespace-manager
apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: studio-backend
namespace: studio
labels:
app: studio-backend
spec:
replicas: 1
selector:
matchLabels:
app: studio-backend
template:
metadata:
labels:
app: studio-backend
spec:
containers:
- name: studio-backend
image: ${REGISTRY}/studio-backend:${TAG}
imagePullPolicy: Always
env:
- name: APP_FRONTEND_IMAGE
value: ${REGISTRY}/app-frontend:${TAG}
- name: APP_BACKEND_IMAGE
value: ${REGISTRY}/app-backend:${TAG}
- name: REGISTRY
value: ${REGISTRY}
- name: TAG
value: ${TAG}
- name: SBX_HTTP_PROXY
value: ${HTTP_PROXY}
- name: SBX_NO_PROXY
value: ${NO_PROXY}
envFrom:
- configMapRef:
name: studio-config
ports:
- containerPort: 5000
resources:
requests:
memory: "1Gi"
cpu: "1"
limits:
memory: "2Gi"
cpu: "2"
livenessProbe:
httpGet:
path: /studio-backend/health
port: 5000
initialDelaySeconds: 60
periodSeconds: 30
timeoutSeconds: 10
failureThreshold: 3
serviceAccountName: studio-backend-sa
---
apiVersion: v1
kind: Service
metadata:
name: studio-frontend
namespace: studio
spec:
type: ClusterIP
ports:
- port: 3000
targetPort: 3000
protocol: TCP
name: studio-frontend
selector:
app: studio-frontend
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: studio-frontend
namespace: studio
labels:
app: studio-frontend
spec:
replicas: 1
selector:
matchLabels:
app: studio-frontend
template:
metadata:
labels:
app: studio-frontend
spec:
securityContext: {}
containers:
- name: studio-frontend
securityContext: {}
image: ${REGISTRY}/studio-frontend:${TAG}
imagePullPolicy: Always
env:
- name: DATABASE_TYPE
value: mysql
- name: DATABASE_HOST
value: ${MYSQL_HOST}
- name: DATABASE_PORT
value: "3306"
- name: DATABASE_USER
value: studio
- name: DATABASE_PASSWORD
value: studio
- name: DATABASE_NAME
value: studio
- name: DATABASE_SSL
value: "true"
ports:
- name: studio-frontend
containerPort: 8080
protocol: TCP
resources: {}
volumeMounts:
- mountPath: /tmp
name: tmp
- name: mysql-tls
mountPath: /etc/mysql/ssl
readOnly: true
volumes:
- name: tmp
emptyDir: {}
- name: mysql-tls
secret:
secretName: mysql-tls
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: keycloak
namespace: studio
labels:
app: keycloak
spec:
replicas: 1
selector:
matchLabels:
app: keycloak
template:
metadata:
labels:
app: keycloak
spec:
initContainers:
- name: keycloak-assets
image: curlimages/curl:latest
command: ["/bin/sh", "-c"]
args:
- |
OWNER=$(echo ${KC_ASSETS_GIT_URL} | sed -E 's|https://github.com/([^/]+)/([^/]+)/tree/([^/]+)/.*|\1|')
REPO=$(echo ${KC_ASSETS_GIT_URL} | sed -E 's|https://github.com/([^/]+)/([^/]+)/tree/([^/]+)/.*|\2|')
BRANCH=$(echo ${KC_ASSETS_GIT_URL} | sed -E 's|https://github.com/[^/]+/[^/]+/tree/([^/]+)/.*|\1|')
KC_ASSETS_DIR=$(echo ${KC_ASSETS_GIT_URL} | sed -E 's|https://github.com/[^/]+/[^/]+/tree/[^/]+/(.*?)/?$|\1|')
if [[ "${KC_ASSETS_DIR: -1}" == "/" ]]; then KC_ASSETS_DIR="${KC_ASSETS_DIR%/}"; fi
DOWNLOAD_URL="https://codeload.github.com/${OWNER}/${REPO}/tar.gz/${BRANCH}"
curl "${DOWNLOAD_URL}" | tar -xz --strip-components=4 -C /opt/keycloak/themes "${REPO}-${BRANCH}/${KC_ASSETS_DIR}/themes"
curl "${DOWNLOAD_URL}" | tar -xz --strip-components=4 -C /opt/keycloak/data "${REPO}-${BRANCH}/${KC_ASSETS_DIR}/data"
envFrom:
- configMapRef:
name: studio-config
volumeMounts:
- name: keycloak-themes-volume
mountPath: /opt/keycloak/themes
- name: keycloak-dataimport-volume
mountPath: /opt/keycloak/data/import
securityContext:
runAsUser: 0
runAsGroup: 0
containers:
- name: keycloak
image: quay.io/keycloak/keycloak:latest
volumeMounts:
- name: mysql-tls
mountPath: /etc/mysql/ssl
readOnly: true
- name: app-tls
mountPath: /etc/ssl
readOnly: true
- name: keycloak-themes-volume
mountPath: /opt/keycloak/themes
- name: keycloak-dataimport-volume
mountPath: /opt/keycloak/data/import
args:
- start
- --import-realm
ports:
- containerPort: 8080
- containerPort: 8443
env:
- name: KC_BOOTSTRAP_ADMIN_USERNAME
value: "admin"
- name: KC_BOOTSTRAP_ADMIN_PASSWORD
value: "admin"
- name: KC_PROXY_HEADERS
value: "forwarded"
- name: KC_HTTP_RELATIVE_PATH
value: "/auth"
- name: KC_PROXY
value: edge
- name: KC_HTTPS_CERTIFICATE_FILE
value: /etc/ssl/app-tls.crt
- name: KC_HTTPS_CERTIFICATE_KEY_FILE
value: /etc/ssl/app-tls.key
- name: KC_HOSTNAME_STRICT
value: "false"
- name: KC_HOSTNAME_STRICT_HTTPS
value: "true"
# Database Configuration for MySQL
- name: KC_DB
value: "mysql"
- name: KC_DB_URL
value: "jdbc:mysql://${MYSQL_HOST}:3306/keycloak?useSSL=true&requireSSL=true&clientCertificateKeyStoreUrl=file:/etc/mysql/ssl/client-keystore.p12&trustCertificateKeyStoreUrl=file:/etc/mysql/ssl/ca.pem"
- name: KC_DB_USERNAME
value: "studio"
- name: KC_DB_PASSWORD
value: "studio"
- name: KC_DB_DATABASE
value: "keycloak"
readinessProbe:
failureThreshold: 3
httpGet:
path: auth/realms/master
port: 8443
scheme: HTTPS
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
resources:
requests:
memory: "512Mi"
cpu: "500m"
limits:
memory: "1Gi"
cpu: "1"
volumes:
- name: app-tls
secret:
secretName: app-tls
- name: mysql-tls
secret:
secretName: mysql-tls
- name: keycloak-themes-volume
emptyDir: {}
- name: keycloak-dataimport-volume
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: keycloak
namespace: studio
spec:
type: ClusterIP
ports:
- name: https
protocol: TCP
port: 8443
targetPort: 8443
selector:
app: keycloak