-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05-comments-service.yml
More file actions
104 lines (102 loc) · 3.24 KB
/
Copy path05-comments-service.yml
File metadata and controls
104 lines (102 loc) · 3.24 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
# ============================================================
# 05-comments-service.yml – Comments Spring Boot service
# ============================================================
#
# CONCEPT: Service independence
# ──────────────────────────────
# This service (Comments) is completely independent of the Documents
# service:
# • It uses its OWN Cassandra node: cassandra:9042
# • It creates its own keyspace before the app starts.
# • It does NOT know the Documents service exists.
#
# This is the "database-per-service" pattern in action.
# ============================================================
# ─── Deployment ──────────────────────────────────────────────────────
apiVersion: apps/v1
kind: Deployment
metadata:
name: comments-service
namespace: dms
labels:
app: comments-service
spec:
replicas: 1
selector:
matchLabels:
app: comments-service
template:
metadata:
labels:
app: comments-service
spec:
initContainers:
- name: wait-for-cassandra
image: busybox:1.36
command:
- sh
- -c
- |
echo "Waiting for cassandra:9042..."
until nc -z cassandra 9042; do
sleep 2
done
echo "Cassandra is reachable!"
- name: ensure-keyspace
image: cassandra:4.1
command:
- sh
- -c
- |
until cqlsh cassandra 9042 -e "CREATE KEYSPACE IF NOT EXISTS dms WITH replication = {'class':'SimpleStrategy','replication_factor':1};"; do
echo "Waiting to create keyspace dms..."
sleep 2
done
echo "Keyspace dms is ready."
containers:
- name: comments-service
image: dms/comments-service:latest
imagePullPolicy: Never
ports:
- containerPort: 8082
env:
- name: CASSANDRA_HOST
value: "cassandra"
- name: CASSANDRA_PORT
value: "9042"
- name: CASSANDRA_DC
value: "datacenter1"
- name: CASSANDRA_KEYSPACE
value: "dms"
- name: MANAGEMENT_ENDPOINT_HEALTH_PROBES_ENABLED
value: "true"
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: 8082
initialDelaySeconds: 30
periodSeconds: 10
failureThreshold: 5
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 8082
initialDelaySeconds: 60
periodSeconds: 20
---
# ─── Service ─────────────────────────────────────────────────────────
apiVersion: v1
kind: Service
metadata:
name: comments-service
namespace: dms
labels:
app: comments-service
spec:
type: ClusterIP
selector:
app: comments-service
ports:
- name: http
port: 8082
targetPort: 8082