-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmulti-tenancy.yaml
More file actions
505 lines (467 loc) · 11.2 KB
/
multi-tenancy.yaml
File metadata and controls
505 lines (467 loc) · 11.2 KB
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
# Multi-Tenancy Example
# This example demonstrates:
# - Multiple databases per cluster for different tenants
# - Resource isolation and quotas
# - Tenant-specific backups
# - Access control and security
---
# Shared infrastructure namespace
apiVersion: v1
kind: Namespace
metadata:
name: neo4j-multi-tenant
labels:
purpose: multi-tenancy
---
# Admin credentials for cluster management
apiVersion: v1
kind: Secret
metadata:
name: cluster-admin-secret
namespace: neo4j-multi-tenant
type: Opaque
stringData:
username: neo4j
password: secure-admin-password
---
# Tenant credentials
apiVersion: v1
kind: Secret
metadata:
name: tenant-a-secret
namespace: neo4j-multi-tenant
type: Opaque
stringData:
username: tenant_a_admin
password: tenantA123!
---
apiVersion: v1
kind: Secret
metadata:
name: tenant-b-secret
namespace: neo4j-multi-tenant
type: Opaque
stringData:
username: tenant_b_admin
password: tenantB123!
---
apiVersion: v1
kind: Secret
metadata:
name: tenant-c-secret
namespace: neo4j-multi-tenant
type: Opaque
stringData:
username: tenant_c_admin
password: tenantC123!
---
# Multi-tenant Neo4j Cluster
apiVersion: neo4j.neo4j.com/v1alpha1
kind: Neo4jEnterpriseCluster
metadata:
name: multi-tenant-cluster
namespace: neo4j-multi-tenant
spec:
image:
repo: neo4j
tag: "5.26.0-enterprise"
# Larger server cluster to handle multiple tenants
topology:
servers: 5 # 5 servers will self-organize to support multiple database topologies
# Resource allocation for multi-tenancy
resources:
requests:
cpu: "4"
memory: "16Gi"
limits:
cpu: "8"
memory: "32Gi"
storage:
className: fast-ssd
size: 200Gi
auth:
adminSecret: cluster-admin-secret
provider: native
# Multi-tenant configuration
configMap:
data:
# Memory allocation
server.memory.heap.initial_size: "8G"
server.memory.heap.max_size: "8G"
server.memory.pagecache.size: "16G"
# Transaction isolation
db.transaction.timeout: "120s"
db.transaction.concurrent.maximum: "1000"
# Query management
db.query.timeout: "300s"
dbms.routing_ttl: "300s"
# Enable database management
dbms.max_databases: "50"
---
# TENANT A: E-commerce Platform
---
# Tenant A main database
apiVersion: neo4j.neo4j.com/v1alpha1
kind: Neo4jDatabase
metadata:
name: tenant-a-production
namespace: neo4j-multi-tenant
labels:
tenant: tenant-a
environment: production
spec:
clusterRef: multi-tenant-cluster
name: tenant_a_prod
wait: true
ifNotExists: true
# Dedicated resources for tenant A
topology:
primaries: 2
secondaries: 1
options:
# Transaction log retention for compliance
txLogEnrichment: "FULL"
txLogRetention: "7 days"
# E-commerce schema
initialData:
source: cypher
cypherStatements:
- "CREATE CONSTRAINT tenant_a_user_id IF NOT EXISTS ON (u:User) ASSERT u.userId IS UNIQUE"
- "CREATE CONSTRAINT tenant_a_product_sku IF NOT EXISTS ON (p:Product) ASSERT p.sku IS UNIQUE"
- "CREATE CONSTRAINT tenant_a_order_id IF NOT EXISTS ON (o:Order) ASSERT o.orderId IS UNIQUE"
- "CREATE INDEX tenant_a_user_email IF NOT EXISTS FOR (u:User) ON (u.email)"
- "CREATE INDEX tenant_a_product_category IF NOT EXISTS FOR (p:Product) ON (p.category)"
---
# Tenant A staging database
apiVersion: neo4j.neo4j.com/v1alpha1
kind: Neo4jDatabase
metadata:
name: tenant-a-staging
namespace: neo4j-multi-tenant
labels:
tenant: tenant-a
environment: staging
spec:
clusterRef: multi-tenant-cluster
name: tenant_a_staging
wait: true
ifNotExists: true
topology:
primaries: 1
secondaries: 1
---
# TENANT B: Social Network
---
# Tenant B database with graph-specific optimizations
apiVersion: neo4j.neo4j.com/v1alpha1
kind: Neo4jDatabase
metadata:
name: tenant-b-production
namespace: neo4j-multi-tenant
labels:
tenant: tenant-b
environment: production
spec:
clusterRef: multi-tenant-cluster
name: tenant_b_social
wait: true
ifNotExists: true
topology:
primaries: 2
secondaries: 2 # More secondaries for read-heavy workload
options:
# Optimized for graph traversals
dbms.memory.transaction.max: "2g"
dbms.memory.transaction.global_max: "4g"
# Social network schema
initialData:
source: cypher
cypherStatements:
- "CREATE CONSTRAINT tenant_b_user_id IF NOT EXISTS ON (u:Person) ASSERT u.personId IS UNIQUE"
- "CREATE CONSTRAINT tenant_b_post_id IF NOT EXISTS ON (p:Post) ASSERT p.postId IS UNIQUE"
- "CREATE INDEX tenant_b_person_name IF NOT EXISTS FOR (p:Person) ON (p.name)"
- "CREATE INDEX tenant_b_post_timestamp IF NOT EXISTS FOR (p:Post) ON (p.timestamp)"
- "CREATE INDEX tenant_b_friendship IF NOT EXISTS FOR ()-[f:FRIENDS_WITH]-() ON (f.since)"
---
# TENANT C: Analytics Platform (Neo4j 2025.x)
---
# Tenant C using Neo4j 2025.x features
apiVersion: neo4j.neo4j.com/v1alpha1
kind: Neo4jDatabase
metadata:
name: tenant-c-analytics
namespace: neo4j-multi-tenant
labels:
tenant: tenant-c
environment: production
spec:
clusterRef: multi-tenant-cluster
name: tenant_c_analytics
wait: true
ifNotExists: true
# Use modern Cypher for analytics
defaultCypherLanguage: "25"
topology:
primaries: 3 # More primaries for parallel analytics
secondaries: 1
options:
# Analytics optimizations
db.query.timeout: "3600s" # 1 hour for complex analytics
dbms.query.cache_size: "2000"
# Analytics schema
initialData:
source: cypher
cypherStatements:
- "CREATE CONSTRAINT tenant_c_metric_id IF NOT EXISTS ON (m:Metric) ASSERT m.metricId IS UNIQUE"
- "CREATE INDEX tenant_c_metric_timestamp IF NOT EXISTS FOR (m:Metric) ON (m.timestamp)"
- "CREATE INDEX tenant_c_metric_type IF NOT EXISTS FOR (m:Metric) ON (m.type)"
---
# Tenant-specific backup configurations
---
# Tenant A daily backups
apiVersion: neo4j.neo4j.com/v1alpha1
kind: Neo4jBackup
metadata:
name: tenant-a-backup
namespace: neo4j-multi-tenant
labels:
tenant: tenant-a
spec:
target:
kind: Database
name: tenant_a_prod
namespace: neo4j-multi-tenant
schedule:
cron: "0 1 * * *" # Daily at 1 AM
storage:
type: s3
bucket: tenant-backups
path: "tenant-a/daily"
cloud:
credentialsSecret: tenant-a-s3-credentials
retention:
maxAge: "30d"
maxCount: 30
---
# Tenant B hourly backups (high-frequency social data)
apiVersion: neo4j.neo4j.com/v1alpha1
kind: Neo4jBackup
metadata:
name: tenant-b-backup
namespace: neo4j-multi-tenant
labels:
tenant: tenant-b
spec:
target:
kind: Database
name: tenant_b_social
namespace: neo4j-multi-tenant
schedule:
cron: "0 * * * *" # Hourly
storage:
type: s3
bucket: tenant-backups
path: "tenant-b/hourly"
cloud:
credentialsSecret: tenant-b-s3-credentials
options:
backupType: "DIFF" # Differential for frequent backups
compress: true
retention:
maxAge: "7d"
maxCount: 168 # 7 days of hourly backups
---
# Tenant C weekly full backups (analytics workload)
apiVersion: neo4j.neo4j.com/v1alpha1
kind: Neo4jBackup
metadata:
name: tenant-c-backup
namespace: neo4j-multi-tenant
labels:
tenant: tenant-c
spec:
target:
kind: Database
name: tenant_c_analytics
namespace: neo4j-multi-tenant
schedule:
cron: "0 3 * * 0" # Weekly on Sunday at 3 AM
storage:
type: s3
bucket: tenant-backups
path: "tenant-c/weekly"
cloud:
credentialsSecret: tenant-c-s3-credentials
options:
backupType: "FULL"
pageCache: "4G" # Large cache for big analytics DB
retention:
maxAge: "90d"
maxCount: 12
---
# Resource Quotas per Tenant
---
apiVersion: v1
kind: ResourceQuota
metadata:
name: tenant-a-quota
namespace: neo4j-multi-tenant
spec:
hard:
requests.cpu: "4"
requests.memory: "16Gi"
persistentvolumeclaims: "5"
---
apiVersion: v1
kind: ResourceQuota
metadata:
name: tenant-b-quota
namespace: neo4j-multi-tenant
spec:
hard:
requests.cpu: "6"
requests.memory: "24Gi"
persistentvolumeclaims: "8"
---
apiVersion: v1
kind: ResourceQuota
metadata:
name: tenant-c-quota
namespace: neo4j-multi-tenant
spec:
hard:
requests.cpu: "8"
requests.memory: "32Gi"
persistentvolumeclaims: "10"
---
# Monitoring per Tenant
---
apiVersion: v1
kind: Service
metadata:
name: tenant-metrics
namespace: neo4j-multi-tenant
labels:
app: neo4j
monitoring: prometheus
spec:
selector:
neo4j.com/cluster: multi-tenant-cluster
ports:
- name: metrics
port: 2004
targetPort: 2004
---
# ServiceMonitor with tenant labels
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: multi-tenant-monitor
namespace: neo4j-multi-tenant
spec:
selector:
matchLabels:
app: neo4j
endpoints:
- port: metrics
interval: 30s
path: /metrics
relabelings:
- sourceLabels: [__meta_kubernetes_pod_label_tenant]
targetLabel: tenant
- sourceLabels: [__meta_kubernetes_pod_label_database]
targetLabel: database
---
# Network Policies for Tenant Isolation
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: tenant-a-network-policy
namespace: neo4j-multi-tenant
spec:
podSelector:
matchLabels:
tenant: tenant-a
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
tenant: tenant-a
- namespaceSelector:
matchLabels:
name: tenant-a-apps
egress:
- to:
- podSelector:
matchLabels:
app: neo4j
- to:
- namespaceSelector: {}
ports:
- protocol: TCP
port: 53 # DNS
---
# Tenant Management Scripts
---
apiVersion: v1
kind: ConfigMap
metadata:
name: tenant-management
namespace: neo4j-multi-tenant
data:
create-tenant.sh: |
#!/bin/bash
# Script to onboard new tenant
TENANT_ID=$1
TENANT_NAME=$2
DB_SIZE=$3 # small, medium, large
# Determine topology based on size
case $DB_SIZE in
small)
PRIMARIES=1
SECONDARIES=1
;;
medium)
PRIMARIES=2
SECONDARIES=1
;;
large)
PRIMARIES=3
SECONDARIES=2
;;
esac
# Create tenant database
kubectl apply -f - <<EOF
apiVersion: neo4j.neo4j.com/v1alpha1
kind: Neo4jDatabase
metadata:
name: ${TENANT_ID}-database
namespace: neo4j-multi-tenant
labels:
tenant: ${TENANT_ID}
spec:
clusterRef: multi-tenant-cluster
name: ${TENANT_ID}_db
wait: true
ifNotExists: true
topology:
primaries: ${PRIMARIES}
secondaries: ${SECONDARIES}
EOF
echo "Tenant ${TENANT_NAME} (${TENANT_ID}) created with ${DB_SIZE} configuration"
monitor-tenants.sh: |
#!/bin/bash
# Monitor tenant resource usage
echo "=== Tenant Database Status ==="
kubectl get neo4jdatabase -n neo4j-multi-tenant -L tenant
echo -e "\n=== Tenant Resource Usage ==="
for tenant in tenant-a tenant-b tenant-c; do
echo "Tenant: $tenant"
kubectl exec -n neo4j-multi-tenant multi-tenant-cluster-0 -- \
cypher-shell -u neo4j -p $ADMIN_PASSWORD \
"SHOW DATABASE ${tenant}_* YIELD name, currentStatus, store"
done